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 | |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 14 | /** |
| 15 | * The "NB" read-only Network Map. |
| 16 | * |
| 17 | * TODO Current implementation directly read from DB, but |
| 18 | * eventually, it should read from In-memory shared Network Map instance within ONOS process. |
| 19 | * |
| 20 | */ |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 21 | public class NetworkGraphImpl implements NetworkGraph { |
| 22 | |
| 23 | private static final Logger log = LoggerFactory.getLogger(NetworkGraphImpl.class); |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 24 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 25 | @Override |
| 26 | public Switch getSwitch(long dpid) { |
| 27 | SwitchImpl sw = new SwitchImpl(this); |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 28 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 29 | RCSwitch rcSwitch = new RCSwitch(dpid); |
| 30 | try { |
| 31 | rcSwitch.read(); |
| 32 | } catch (ObjectDoesntExistException e) { |
| 33 | log.warn("Tried to get a switch that doesn't exist {}", dpid); |
| 34 | return null; |
| 35 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 36 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 37 | sw.setDpid(rcSwitch.getDpid()); |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 38 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 39 | for (byte[] portId : rcSwitch.getAllPortIds()) { |
| 40 | RCPort rcPort = RCPort.createFromKey(portId); |
| 41 | try { |
| 42 | rcPort.read(); |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 43 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 44 | PortImpl port = new PortImpl(this); |
| 45 | //port.setDpid(dpid); |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 46 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 47 | // TODO why are port numbers long? |
| 48 | //port.setPortNumber((short)rcPort.getNumber()); |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 49 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 50 | port.setSwitch(sw); |
| 51 | sw.addPort(port); |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 52 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 53 | } catch (ObjectDoesntExistException e) { |
| 54 | log.warn("Tried to read port that doesn't exist", rcPort); |
| 55 | } |
| 56 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 57 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 58 | return sw; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public Iterable<Switch> getSwitches() { |
| 63 | // TODO Auto-generated method stub |
| 64 | return null; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public Iterable<Link> getLinks() { |
| 69 | // TODO Auto-generated method stub |
| 70 | return null; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public Iterable<Link> getLinksFromSwitch(long dpid) { |
| 75 | // TODO Auto-generated method stub |
| 76 | return null; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public Iterable<Device> getDeviceByIp(InetAddress ipAddress) { |
| 81 | // TODO Auto-generated method stub |
| 82 | return null; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public Iterable<Device> getDeviceByMac(MACAddress address) { |
| 87 | // TODO Auto-generated method stub |
| 88 | return null; |
| 89 | } |
| 90 | |
| 91 | } |