blob: 29cc1d7ed0bee4ca55ba34924a3a23dc11cb42a3 [file] [log] [blame]
Jonathan Hart062a2e82014-02-03 09:41:57 -08001package net.onrc.onos.ofcontroller.networkgraph;
2
Jonathan Hart062a2e82014-02-03 09:41:57 -08003import net.onrc.onos.datastore.topology.RCPort;
4import net.onrc.onos.datastore.topology.RCSwitch;
5
6import org.slf4j.Logger;
7import org.slf4j.LoggerFactory;
8
9import edu.stanford.ramcloud.JRamCloud.ObjectDoesntExistException;
10
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080011/**
12 * The "NB" read-only Network Map.
13 *
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080014 * TODO Current implementation directly read from DB, but eventually, it should
15 * read from In-memory shared Network Map instance within ONOS process.
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080016 *
17 */
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080018public class NetworkGraphImpl extends AbstractNetworkGraph {
Jonathan Hart062a2e82014-02-03 09:41:57 -080019
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080020 private static final Logger log = LoggerFactory
21 .getLogger(NetworkGraphImpl.class);
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080022
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080023 public NetworkGraphImpl() {
24 super();
25 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080026
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080027 void addSwitch(Switch sw) {
28 if ( sw == null ) {
29 throw new IllegalArgumentException("Switch cannot be null");
30 }
31 switches.put(sw.getDpid(), sw);
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080032
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080033 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080034
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080035 /**
36 * Deactivate Switch (and its Ports)
37 * @param sw
38 */
39 void deactivateSwitch(Switch sw) {
40 if ( sw == null ) {
41 throw new IllegalArgumentException("Switch cannot be null");
42 }
43 SwitchImpl s = getSwitchImpl(sw);
44 // TODO Deactivate Switch
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080045
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080046 // XXX Are we sure we want to deactivate Ports also?
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080047
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080048 // TODO Auto-generated method stub
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080049
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080050 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080051
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080052 void addPort(Port port) {
53 if ( port == null ) {
54 throw new IllegalArgumentException("Port cannot be null");
55 }
56 // TODO Auto-generated method stub
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080057
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080058 }
59
60 void deactivatePort(Port port) {
61 if ( port == null ) {
62 throw new IllegalArgumentException("Port cannot be null");
63 }
64 // TODO Auto-generated method stub
65
66 }
67
68 void addLink(Link link) {
69 if ( link == null ) {
70 throw new IllegalArgumentException("Link cannot be null");
71 }
72 // TODO Auto-generated method stub
73
74 }
75
76 void removeLink(Link link) {
77 if ( link == null ) {
78 throw new IllegalArgumentException("Link cannot be null");
79 }
80 // TODO Auto-generated method stub
81
82 }
83
84 void updateDevice(Device device) {
85 if ( device == null ) {
86 throw new IllegalArgumentException("Device cannot be null");
87 }
88 // TODO Auto-generated method stub
89
90 }
91
92 void removeDevice(Device device) {
93 if ( device == null ) {
94 throw new IllegalArgumentException("Device cannot be null");
95 }
96 // TODO Auto-generated method stub
97
98 }
99
100 private SwitchImpl getSwitchImpl(Switch sw) {
101 if( sw instanceof SwitchImpl ) {
102 return (SwitchImpl) sw;
103 }
104 throw new ClassCastException("SwitchImpl expected, but found:" + sw.getClass().getName() );
105 }
106
107 // FIXME To be removed later this class should never read from DB.
108 public void readSwitchFromTopology(long dpid) {
109 SwitchImpl sw = new SwitchImpl(this);
110
111 RCSwitch rcSwitch = new RCSwitch(dpid);
112 try {
113 rcSwitch.read();
114 } catch (ObjectDoesntExistException e) {
115 log.warn("Tried to get a switch that doesn't exist {}", dpid);
116 return;
Jonathan Hart062a2e82014-02-03 09:41:57 -0800117 }
118
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800119 sw.setDpid(rcSwitch.getDpid());
120
121 addSwitch(sw);
122
123 for (byte[] portId : rcSwitch.getAllPortIds()) {
124 RCPort rcPort = RCPort.createFromKey(portId);
125 try {
126 rcPort.read();
127
128 PortImpl port = new PortImpl(this);
129 // port.setDpid(dpid);
130
131 // TODO why are port numbers long?
132 // port.setPortNumber((short)rcPort.getNumber());
133
134 port.setSwitch(sw);
135 sw.addPort(port);
136
137 addPort(port);
138
139 } catch (ObjectDoesntExistException e) {
140 log.warn("Tried to read port that doesn't exist", rcPort);
141 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800142 }
143
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800144 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800145
146}