blob: 539ca63927f435d5187812dcf8b4d426e7fd8ae1 [file] [log] [blame]
Jonathan Hart062a2e82014-02-03 09:41:57 -08001package net.onrc.onos.ofcontroller.networkgraph;
2
Yuta HIGUCHIcb951982014-02-11 13:31:44 -08003import java.net.InetAddress;
4import java.util.Set;
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -08005
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -08006import net.onrc.onos.datastore.topology.RCLink;
Jonathan Hart062a2e82014-02-03 09:41:57 -08007import net.onrc.onos.datastore.topology.RCPort;
8import net.onrc.onos.datastore.topology.RCSwitch;
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -08009import net.onrc.onos.ofcontroller.util.Dpid;
Jonathan Hart062a2e82014-02-03 09:41:57 -080010
11import org.slf4j.Logger;
12import org.slf4j.LoggerFactory;
13
14import edu.stanford.ramcloud.JRamCloud.ObjectDoesntExistException;
15
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080016/**
17 * The "NB" read-only Network Map.
18 *
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080019 * - Maintain Invariant/Relationships between Topology Objects.
20 *
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -080021 * TODO To be synchronized based on TopologyEvent Notification.
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080022 *
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080023 * TODO TBD: Caller is expected to maintain parent/child calling order. Parent
24 * Object must exist before adding sub component(Add Switch -> Port). Child
25 * Object need to be removed before removing parent (Delete Port->Switch)
26 *
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080027 * TODO TBD: This class may delay the requested change to handle event
28 * re-ordering. e.g.) Link Add came in, but Switch was not there.
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080029 *
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080030 */
Jonathan Hart22eb9882014-02-11 15:52:59 -080031public class NetworkGraphImpl extends AbstractNetworkGraph
32 implements NetworkGraphDiscoveryInterface {
Jonathan Hart062a2e82014-02-03 09:41:57 -080033
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080034 private static final Logger log = LoggerFactory
35 .getLogger(NetworkGraphImpl.class);
Jonathan Hart22eb9882014-02-11 15:52:59 -080036
37 private final NetworkGraphDatastore datastore;
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080038
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080039 public NetworkGraphImpl() {
40 super();
Jonathan Hart22eb9882014-02-11 15:52:59 -080041 datastore = new NetworkGraphDatastore(this);
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080042 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080043
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080044 /**
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080045 * put Switch
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080046 *
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080047 * XXX Internal Invariant-maintenance method. Will not write to DB. Will not
48 * fire Notification.
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080049 *
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080050 * @param swEvt
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080051 */
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080052 void putSwitch(SwitchEvent swEvt) {
53 if (swEvt == null) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080054 throw new IllegalArgumentException("Switch cannot be null");
55 }
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080056 Switch sw = switches.get(swEvt.getDpid());
57
58 if (sw == null) {
59 sw = new SwitchImpl(this, swEvt.getDpid());
60 Switch existing = switches.putIfAbsent(swEvt.getDpid(), sw);
61 if (existing != null) {
62 log.warn(
63 "Concurrent putSwitch not expected. Continuing updating {}",
64 existing);
65 sw = existing;
66 }
67 }
68
69 // Add upate when more attributes are added to Event object
70 // no attribute to update for now
71 }
72
73 /**
74 * remove Switch.
75 *
76 * XXX Internal Invariant-maintenance method. Will not write to DB. Will not
77 * fire Notification.
78 *
79 * @param swEvt
80 */
81 void removeSwitch(SwitchEvent swEvt) {
82 if (swEvt == null) {
83 throw new IllegalArgumentException("Switch cannot be null");
84 }
85
86 Switch sw = switches.get(swEvt.getDpid());
87
88 if (sw == null) {
89 log.warn("Switch {} already removed, ignoreing", swEvt);
90 return;
91 }
92
93 // Sanity check
94 if (!sw.getPorts().isEmpty()) {
95 log.warn(
96 "Ports on Switch {} should be removed prior to removing Switch. Removing Switch anyways",
97 swEvt);
98 // XXX Should we remove Port?
99 }
100 if (!sw.getDevices().isEmpty()) {
101 log.warn(
102 "Devices on Switch {} should be removed prior to removing Switch. Removing Switch anyways",
103 swEvt);
104 // XXX Should we remove Device to Switch relation?
105 }
106 if (!sw.getIncomingLinks().iterator().hasNext()) {
107 log.warn(
108 "IncomingLinks on Switch {} should be removed prior to removing Switch. Removing Switch anyways",
109 swEvt);
110 // XXX Should we remove Link?
111 }
112 if (!sw.getOutgoingLinks().iterator().hasNext()) {
113 log.warn(
114 "OutgoingLinks on Switch {} should be removed prior to removing Switch. Removing Switch anyways",
115 swEvt);
116 // XXX Should we remove Link?
117 }
118
119 boolean removed = switches.remove(swEvt.getDpid(), sw);
120 if (removed) {
121 log.warn(
122 "Switch instance was replaced concurrently while removing {}. Something is not right.",
123 sw);
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800124 }
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800125 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -0800126
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800127 /**
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800128 * put Port
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800129 *
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800130 * XXX Internal Invariant-maintenance method. Will not write to DB. Will not
131 * fire Notification.
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800132 *
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800133 * @param portEvt
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800134 */
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800135 void putPort(PortEvent portEvt) {
136 if (portEvt == null) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800137 throw new IllegalArgumentException("Port cannot be null");
138 }
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800139 Switch sw = switches.get(portEvt.getDpid());
140 if (sw == null) {
141 throw new BrokenInvariantException(String.format(
142 "Switch with dpid %s did not exist.",
143 new Dpid(portEvt.getDpid())));
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800144 }
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800145 Port p = sw.getPort(portEvt.getNumber());
146 PortImpl port = null;
147 if (p != null) {
148 port = getPortImpl(p);
149 }
150
151 if (port == null) {
152 port = new PortImpl(this, sw, portEvt.getNumber());
153 }
154
155 // TODO update attributes
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800156
157 SwitchImpl s = getSwitchImpl(sw);
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800158 s.addPort(port);
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800159 }
160
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800161 /**
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800162 * remove Port
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800163 *
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800164 * XXX Internal Invariant-maintenance method. Will not write to DB. Will not
165 * fire Notification.
166 *
167 * @param portEvt
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800168 */
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800169 void removePort(PortEvent portEvt) {
170 if (portEvt == null) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800171 throw new IllegalArgumentException("Port cannot be null");
172 }
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800173
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800174 Switch sw = switches.get(portEvt.getDpid());
175 if (sw == null) {
176 log.warn("Parent Switch for Port {} already removed, ignoreing", portEvt);
177 return;
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800178 }
179
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800180 Port p = sw.getPort(portEvt.getNumber());
181 if (p == null) {
182 log.warn("Port {} already removed, ignoreing", portEvt);
183 return;
184 }
185 // null check
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800186
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800187 if (!p.getDevices().iterator().hasNext()) {
188 log.warn(
189 "Devices on Port {} should be removed prior to removing Port. Removing Port anyways",
190 portEvt);
191 // XXX Should we remove Device to Port relation?
192 }
193 if (p.getIncomingLink() != null) {
194 log.warn(
195 "IncomingLinks on Port {} should be removed prior to removing Port. Removing Port anyways",
196 portEvt);
197 // XXX Should we remove Link?
198 }
199 if (p.getOutgoingLink() != null) {
200 log.warn(
201 "OutgoingLinks on Port {} should be removed prior to removing Port. Removing Port anyways",
202 portEvt);
203 // XXX Should we remove Link?
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800204 }
205
206 // remove Port from Switch
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800207 SwitchImpl s = getSwitchImpl(sw);
208 s.removePort(p);
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800209 }
210
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800211 /**
212 * put Link
213 *
214 * XXX Internal Invariant-maintenance method. Will not write to DB. Will not
215 * fire Notification.
216 *
217 * @param linkEvt
218 */
219 void putLink(LinkEvent linkEvt) {
220 if (linkEvt == null) {
221 throw new IllegalArgumentException("Link cannot be null");
222 }
223 // TODO Auto-generated method stub
224
225 Switch srcSw = switches.get(linkEvt.getSrc().dpid);
226 if (srcSw == null) {
227 throw new BrokenInvariantException(
228 String.format(
229 "Switch with dpid %s did not exist.",
230 new Dpid(linkEvt.getSrc().dpid)));
231 }
232
233 Switch dstSw = switches.get(linkEvt.getDst().dpid);
234 if (dstSw == null) {
235 throw new BrokenInvariantException(
236 String.format(
237 "Switch with dpid %s did not exist.",
238 new Dpid(linkEvt.getDst().dpid)));
239 }
240
241 Port srcPort = srcSw.getPort(linkEvt.getSrc().number);
242 if (srcPort == null) {
243 throw new BrokenInvariantException(
244 String.format(
245 "Src Port %s of a Link did not exist.",
246 linkEvt.getSrc() ));
247 }
248 Port dstPort = dstSw.getPort(linkEvt.getDst().number);
249 if (dstPort == null) {
250 throw new BrokenInvariantException(
251 String.format(
252 "Dst Port %s of a Link did not exist.",
253 linkEvt.getDst() ));
254 }
255
256 Link l = dstPort.getIncomingLink();
257 LinkImpl link = null;
258 assert( l == srcPort.getOutgoingLink() );
259 if (l != null) {
260// link = getLink
261 }
262
263 // TODO update Switch
264 // TODO update Link
265
266
267 // XXX check Existing Link first?
268// srcPort.setOutgoingLink(link);
269// dstPort.setIncomingLink(link);
270 }
271
272 /**
273 * removeLink
274 *
275 * XXX Internal Invariant-maintenance method. Will not write to DB. Will not
276 * fire Notification.
277 *
278 * @param link
279 */
280 void removeLink(LinkEvent link) {
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800281 if (link == null) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800282 throw new IllegalArgumentException("Link cannot be null");
283 }
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800284 // TODO Auto-generated method stub
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800285
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800286 // Switch srcSw = link.getSourceSwitch();
287 // if (!isSwitchInstanceInTopology(srcSw)) {
288 // // XXX Define or choose more appropriate Exception.
289 // throw new RuntimeException(
290 // String.format(
291 // "Switch with dpid %s did not exist or different instance registered.",
292 // new Dpid(srcSw.getDpid())));
293 // }
294 //
295 // Switch dstSw = link.getDestinationSwitch();
296 // if (!isSwitchInstanceInTopology(dstSw)) {
297 // // XXX Define or choose more appropriate Exception.
298 // throw new RuntimeException(
299 // String.format(
300 // "Switch with dpid %s did not exist or different instance registered.",
301 // new Dpid(dstSw.getDpid())));
302 // }
303 //
304 // PortImpl srcPort = getPortImpl(link.getSourcePort());
305 // PortImpl dstPort = getPortImpl(link.getDestinationPort());
306 //
307 // // XXX check Existing Link first?
308 // if (srcPort.getOutgoingLink() != link
309 // || dstPort.getIncomingLink() != link) {
310 // // XXX Define or choose more appropriate Exception.
311 // throw new RuntimeException(String.format(
312 // "Link %s did not belong to Topology", link.toString()));
313 // }
314 // // remove Link
315 // srcPort.setOutgoingLink(null);
316 // dstPort.setIncomingLink(null);
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800317 }
318
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800319 // XXX Need to rework Device related
320 /**
321 * Add new device to DB
322 *
323 * @param device
324 */
325 void updateDevice(DeviceEvent deviceToUpdate,
326 Set<InetAddress> updatedIpAddrs, Set<Port> updatedAttachmentPoints) {
327 if (deviceToUpdate == null) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800328 throw new IllegalArgumentException("Device cannot be null");
329 }
330 // TODO Auto-generated method stub
331
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800332 // Device existingDevice =
333 // getDeviceByMac(deviceToUpdate.getMacAddress());
334 // if (existingDevice != deviceToUpdate) {
335 // throw new IllegalArgumentException(
336 // "Must supply Device Object in this NetworkGraph");
337 // }
338 //
339 // DeviceImpl device = getDeviceImpl(deviceToUpdate);
340 //
341 // // Update IP Addr
342 // // uniq
343 // Set<InetAddress> prevAddrs = new HashSet<>(
344 // deviceToUpdate.getIpAddress());
345 // Set<InetAddress> newAddrs = updatedIpAddrs;
346 //
347 // // delta
348 // @SuppressWarnings("unchecked")
349 // Collection<InetAddress> delAddr = CollectionUtils.subtract(newAddrs,
350 // prevAddrs);
351 // @SuppressWarnings("unchecked")
352 // Collection<InetAddress> addAddr = CollectionUtils.subtract(prevAddrs,
353 // newAddrs);
354 //
355 // for (InetAddress addr : delAddr) {
356 // Set<Device> devices = addr2Device.get(addr);
357 // if (devices == null) {
358 // continue;
359 // }
360 // devices.remove(device);
361 // device.removeIpAddress(addr);
362 // }
363 // for (InetAddress addr : addAddr) {
364 // Set<Device> devices = addr2Device.get(addr);
365 // if (devices == null) {
366 // devices = new HashSet<>();
367 // addr2Device.put(addr, devices);
368 // }
369 // devices.add(device);
370 // device.addIpAddress(addr);
371 // }
372 //
373 // // Update Attachment Point
374 // // uniq
375 // Set<Port> prevPorts = new HashSet<>();
376 // CollectionUtils.addAll(prevAddrs,
377 // deviceToUpdate.getAttachmentPoints()
378 // .iterator());
379 // Set<Port> newPorts = updatedAttachmentPoints;
380 // // delta
381 // @SuppressWarnings("unchecked")
382 // Collection<Port> delPorts = CollectionUtils.subtract(newPorts,
383 // prevPorts);
384 // @SuppressWarnings("unchecked")
385 // Collection<Port> addPorts = CollectionUtils.subtract(prevPorts,
386 // newPorts);
387 //
388 // for (Port p : delPorts) {
389 // device.removeAttachmentPoint(p);
390 // getPortImpl(p).removeDevice(device);
391 // }
392 //
393 // for (Port p : addPorts) {
394 // device.addAttachmentPoint(p);
395 // getPortImpl(p).addDevice(device);
396 // }
397
398 // TODO Auto-generated method stub
399
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800400 }
401
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800402 void removeDevice(DeviceEvent device) {
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800403 if (device == null) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800404 throw new IllegalArgumentException("Device cannot be null");
405 }
406 // TODO Auto-generated method stub
407
408 }
409
410 private SwitchImpl getSwitchImpl(Switch sw) {
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800411 if (sw instanceof SwitchImpl) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800412 return (SwitchImpl) sw;
413 }
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800414 throw new ClassCastException("SwitchImpl expected, but found: " + sw);
415 }
416
417 private PortImpl getPortImpl(Port p) {
418 if (p instanceof PortImpl) {
419 return (PortImpl) p;
420 }
421 throw new ClassCastException("PortImpl expected, but found: " + p);
422 }
423
Yuta HIGUCHIc0366272014-02-10 21:04:57 -0800424 private DeviceImpl getDeviceImpl(Device d) {
425 if (d instanceof DeviceImpl) {
426 return (DeviceImpl) d;
427 }
428 throw new ClassCastException("DeviceImpl expected, but found: " + d);
429 }
430
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800431 public boolean isSwitchInstanceInTopology(Switch sw) {
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800432 // check if the sw instance is valid in Topology
433 if (sw != switches.get(sw.getDpid())) {
434 return false;
435 }
436 return true;
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800437 }
438
439 public void loadWholeTopologyFromDB() {
440 // XXX clear everything first?
441
442 for (RCSwitch sw : RCSwitch.getAllSwitches()) {
443 try {
444 sw.read();
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800445 // TODO if there is going to be inactive Switch in DB, skip
446 // TODO update other attributes if there exist any
447 putSwitch(new SwitchEvent(sw.getDpid()));
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800448 } catch (ObjectDoesntExistException e) {
449 log.error("Read Switch Failed, skipping", e);
450 }
451 }
452
453 for (RCPort p : RCPort.getAllPorts()) {
454 try {
455 p.read();
456
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800457 Switch sw = this.getSwitch(p.getDpid());
458 if (sw == null) {
459 log.error("Switch {} missing when adding Port {}",
460 new Dpid(p.getDpid()), p);
461 continue;
462 }
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800463 PortEvent portEvent = new PortEvent(p.getDpid(), p.getNumber());
464 // TODO update other attributes if there exist any
465 putPort(portEvent);
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800466 } catch (ObjectDoesntExistException e) {
467 log.error("Read Port Failed, skipping", e);
468 }
469 }
470
471 // TODO Is Device going to be in DB? If so, read from DB.
472 // for (RCDevice d : RCDevice.getAllDevices()) {
473 // try {
474 // d.read();
475 //
476 // } catch (ObjectDoesntExistException e) {
477 // log.debug("Read Device Failed, skipping", e);
478 // }
479 // }
480
481 for (RCLink l : RCLink.getAllLinks()) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800482 try {
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800483 l.read();
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800484
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800485 Switch srcSw = this.getSwitch(l.getSrc().dpid);
486 if (srcSw == null) {
487 log.error("Switch {} missing when adding Link {}",
488 new Dpid(l.getSrc().dpid), l);
489 continue;
490 }
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800491
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800492 Switch dstSw = this.getSwitch(l.getDst().dpid);
493 if (dstSw == null) {
494 log.error("Switch {} missing when adding Link {}",
495 new Dpid(l.getDst().dpid), l);
496 continue;
497 }
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800498
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800499 LinkEvent linkEvent = new LinkEvent(l.getSrc().dpid,
500 l.getSrc().number, l.getDst().dpid, l.getDst().number);
501 // TODO update other attributes if there exist any
502 putLink(linkEvent);
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800503 } catch (ObjectDoesntExistException e) {
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800504 log.debug("Delete Link Failed", e);
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800505 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800506 }
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800507 }
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800508
509 /**
510 * Exception to be thrown when Modification to the Network Graph cannot be continued due to broken invariant.
511 *
512 * XXX Should this be checked exception or RuntimeException
513 */
514 public static class BrokenInvariantException extends RuntimeException {
515 private static final long serialVersionUID = 1L;
516
517 public BrokenInvariantException() {
518 super();
519 }
520
521 public BrokenInvariantException(String message) {
522 super(message);
523 }
524 }
Jonathan Hart22eb9882014-02-11 15:52:59 -0800525
526 /* ******************************
527 * NetworkGraphDiscoveryInterface methods
528 * ******************************/
529
530 @Override
531 public void putSwitchEvent(SwitchEvent switchEvent) {
532 if (checkAddSwitchInvariant()) {
533 datastore.addSwitch(switchEvent);
534 putSwitch(switchEvent);
535 }
536 // TODO handle invariant violation
537 }
538
539 @Override
540 public void removeSwitchEvent(SwitchEvent switchEvent) {
541 if (checkRemoveSwitchInvariant()) {
542 datastore.deactivateSwitch(switchEvent);
543 removeSwitch(switchEvent);
544 }
545 // TODO handle invariant violation
546 }
547
548 @Override
549 public void putPortEvent(PortEvent portEvent) {
550 // TODO Auto-generated method stub
551
552 }
553
554 @Override
555 public void removePortEvent(PortEvent portEvent) {
556 // TODO Auto-generated method stub
557
558 }
559
560 @Override
561 public void putLinkEvent(LinkEvent linkEvent) {
562 if (checkAddLinkInvariant()) {
563 datastore.addLink(linkEvent);
564 putLink(linkEvent);
565 }
566 // TODO handle invariant violation
567 }
568
569 @Override
570 public void removeLinkEvent(LinkEvent linkEvent) {
571 if (checkRemoveLinkInvariant()) {
572 datastore.removeLink(linkEvent);
573 removeLink(linkEvent);
574 }
575 // TODO handle invariant violation
576 }
577
578 @Override
579 public void updateDeviceEvent(DeviceEvent deviceToUpdate,
580 Set<InetAddress> updatedIpAddrs, Set<Port> updatedAttachmentPoints) {
581 // TODO Auto-generated method stub
582
583 }
584
585 @Override
586 public void removeDeviceEvent(DeviceEvent deviceEvent) {
587 // TODO Auto-generated method stub
588
589 }
590
591 /* *****************
592 * Internal methods to check invariants of the network graph
593 * *****************/
594
595 private boolean checkAddSwitchInvariant() {
596 // TODO implement
597 return true;
598 }
599
600 private boolean checkRemoveSwitchInvariant() {
601 // TODO implement
602 return true;
603 }
604
605 private boolean checkAddPortInvariant() {
606 // TODO implement
607 return true;
608 }
609
610 private boolean checkRemovePortInvariant() {
611 // TODO implement
612 return true;
613 }
614
615 private boolean checkAddLinkInvariant() {
616 // TODO implement
617 return true;
618 }
619
620 private boolean checkRemoveLinkInvariant() {
621 // TODO implement
622 return true;
623 }
624
625 private boolean checkAddDeviceInvariant() {
626 // TODO implement
627 return true;
628 }
629
630 private boolean checkRemoveDeviceInvariant() {
631 // TODO implement
632 return true;
633 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800634}