blob: 0530147ac3174613fe687508149e3720f1c0f0ea [file] [log] [blame]
Jonathan Hart062a2e82014-02-03 09:41:57 -08001package net.onrc.onos.ofcontroller.networkgraph;
2
3import java.net.InetAddress;
4
5import net.floodlightcontroller.util.MACAddress;
6import net.onrc.onos.datastore.topology.RCPort;
7import net.onrc.onos.datastore.topology.RCSwitch;
8
9import org.slf4j.Logger;
10import org.slf4j.LoggerFactory;
11
12import edu.stanford.ramcloud.JRamCloud.ObjectDoesntExistException;
13
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080014/**
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 Hart062a2e82014-02-03 09:41:57 -080021public class NetworkGraphImpl implements NetworkGraph {
22
23 private static final Logger log = LoggerFactory.getLogger(NetworkGraphImpl.class);
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080024
Jonathan Hart062a2e82014-02-03 09:41:57 -080025 @Override
26 public Switch getSwitch(long dpid) {
27 SwitchImpl sw = new SwitchImpl(this);
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080028
Jonathan Hart062a2e82014-02-03 09:41:57 -080029 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 HIGUCHI181d34d2014-02-05 15:05:46 -080036
Jonathan Hart062a2e82014-02-03 09:41:57 -080037 sw.setDpid(rcSwitch.getDpid());
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080038
Jonathan Hart062a2e82014-02-03 09:41:57 -080039 for (byte[] portId : rcSwitch.getAllPortIds()) {
40 RCPort rcPort = RCPort.createFromKey(portId);
41 try {
42 rcPort.read();
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080043
Jonathan Hart062a2e82014-02-03 09:41:57 -080044 PortImpl port = new PortImpl(this);
45 //port.setDpid(dpid);
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080046
Jonathan Hart062a2e82014-02-03 09:41:57 -080047 // TODO why are port numbers long?
48 //port.setPortNumber((short)rcPort.getNumber());
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080049
Jonathan Hart062a2e82014-02-03 09:41:57 -080050 port.setSwitch(sw);
51 sw.addPort(port);
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080052
Jonathan Hart062a2e82014-02-03 09:41:57 -080053 } catch (ObjectDoesntExistException e) {
54 log.warn("Tried to read port that doesn't exist", rcPort);
55 }
56 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080057
Jonathan Hart062a2e82014-02-03 09:41:57 -080058 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}