Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame^] | 1 | package net.onrc.onos.ofcontroller.networkgraph; |
| 2 | |
| 3 | import java.net.InetAddress; |
| 4 | |
| 5 | import net.floodlightcontroller.util.MACAddress; |
| 6 | import net.onrc.onos.datastore.topology.RCPort; |
| 7 | import net.onrc.onos.datastore.topology.RCSwitch; |
| 8 | |
| 9 | import org.slf4j.Logger; |
| 10 | import org.slf4j.LoggerFactory; |
| 11 | |
| 12 | import edu.stanford.ramcloud.JRamCloud.ObjectDoesntExistException; |
| 13 | |
| 14 | public class NetworkGraphImpl implements NetworkGraph { |
| 15 | |
| 16 | private static final Logger log = LoggerFactory.getLogger(NetworkGraphImpl.class); |
| 17 | |
| 18 | @Override |
| 19 | public Switch getSwitch(long dpid) { |
| 20 | SwitchImpl sw = new SwitchImpl(this); |
| 21 | |
| 22 | RCSwitch rcSwitch = new RCSwitch(dpid); |
| 23 | try { |
| 24 | rcSwitch.read(); |
| 25 | } catch (ObjectDoesntExistException e) { |
| 26 | log.warn("Tried to get a switch that doesn't exist {}", dpid); |
| 27 | return null; |
| 28 | } |
| 29 | |
| 30 | sw.setDpid(rcSwitch.getDpid()); |
| 31 | |
| 32 | for (byte[] portId : rcSwitch.getAllPortIds()) { |
| 33 | RCPort rcPort = RCPort.createFromKey(portId); |
| 34 | try { |
| 35 | rcPort.read(); |
| 36 | |
| 37 | PortImpl port = new PortImpl(this); |
| 38 | //port.setDpid(dpid); |
| 39 | |
| 40 | // TODO why are port numbers long? |
| 41 | //port.setPortNumber((short)rcPort.getNumber()); |
| 42 | |
| 43 | port.setSwitch(sw); |
| 44 | sw.addPort(port); |
| 45 | |
| 46 | } catch (ObjectDoesntExistException e) { |
| 47 | log.warn("Tried to read port that doesn't exist", rcPort); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | return sw; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public Iterable<Switch> getSwitches() { |
| 56 | // TODO Auto-generated method stub |
| 57 | return null; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public Iterable<Link> getLinks() { |
| 62 | // TODO Auto-generated method stub |
| 63 | return null; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public Iterable<Link> getLinksFromSwitch(long dpid) { |
| 68 | // TODO Auto-generated method stub |
| 69 | return null; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public Iterable<Device> getDeviceByIp(InetAddress ipAddress) { |
| 74 | // TODO Auto-generated method stub |
| 75 | return null; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public Iterable<Device> getDeviceByMac(MACAddress address) { |
| 80 | // TODO Auto-generated method stub |
| 81 | return null; |
| 82 | } |
| 83 | |
| 84 | } |