blob: 99664748c8b99fdacbe19efd263562be7ad2e8c4 [file] [log] [blame]
Jonathan Hart062a2e82014-02-03 09:41:57 -08001package net.onrc.onos.ofcontroller.networkgraph;
2
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -08003import net.onrc.onos.datastore.topology.RCLink;
Jonathan Hart062a2e82014-02-03 09:41:57 -08004import net.onrc.onos.datastore.topology.RCPort;
5import net.onrc.onos.datastore.topology.RCSwitch;
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -08006import net.onrc.onos.ofcontroller.util.Dpid;
Jonathan Hart062a2e82014-02-03 09:41:57 -08007
8import org.slf4j.Logger;
9import org.slf4j.LoggerFactory;
10
11import edu.stanford.ramcloud.JRamCloud.ObjectDoesntExistException;
12
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080013/**
14 * The "NB" read-only Network Map.
15 *
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080016 * - Maintain Invariant/Relationships between Topology Objects.
17 *
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -080018 * TODO To be synchronized based on TopologyEvent Notification.
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080019 *
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080020 * TODO TBD: Caller is expected to maintain parent/child calling order. Parent
21 * Object must exist before adding sub component(Add Switch -> Port). Child
22 * Object need to be removed before removing parent (Delete Port->Switch)
23 *
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080024 * TODO TBD: This class may delay the requested change to handle event
25 * re-ordering. e.g.) Link Add came in, but Switch was not there.
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080026 *
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080027 */
Jonathan Hart22eb9882014-02-11 15:52:59 -080028public class NetworkGraphImpl extends AbstractNetworkGraph
29 implements NetworkGraphDiscoveryInterface {
Jonathan Hart062a2e82014-02-03 09:41:57 -080030
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080031 private static final Logger log = LoggerFactory
32 .getLogger(NetworkGraphImpl.class);
Jonathan Hart22eb9882014-02-11 15:52:59 -080033
34 private final NetworkGraphDatastore datastore;
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080035
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080036 public NetworkGraphImpl() {
37 super();
Jonathan Hart22eb9882014-02-11 15:52:59 -080038 datastore = new NetworkGraphDatastore(this);
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080039 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080040
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080041 /**
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080042 * put Switch
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080043 *
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080044 * XXX Internal Invariant-maintenance method. Will not write to DB. Will not
45 * fire Notification.
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080046 *
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080047 * @param swEvt
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080048 */
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080049 void putSwitch(SwitchEvent swEvt) {
50 if (swEvt == null) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -080051 throw new IllegalArgumentException("Switch cannot be null");
52 }
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080053 Switch sw = switches.get(swEvt.getDpid());
54
55 if (sw == null) {
56 sw = new SwitchImpl(this, swEvt.getDpid());
57 Switch existing = switches.putIfAbsent(swEvt.getDpid(), sw);
58 if (existing != null) {
59 log.warn(
60 "Concurrent putSwitch not expected. Continuing updating {}",
61 existing);
62 sw = existing;
63 }
64 }
65
66 // Add upate when more attributes are added to Event object
67 // no attribute to update for now
68 }
69
70 /**
71 * remove Switch.
72 *
73 * XXX Internal Invariant-maintenance method. Will not write to DB. Will not
74 * fire Notification.
75 *
76 * @param swEvt
77 */
78 void removeSwitch(SwitchEvent swEvt) {
79 if (swEvt == null) {
80 throw new IllegalArgumentException("Switch cannot be null");
81 }
82
83 Switch sw = switches.get(swEvt.getDpid());
84
85 if (sw == null) {
86 log.warn("Switch {} already removed, ignoreing", swEvt);
87 return;
88 }
89
90 // Sanity check
91 if (!sw.getPorts().isEmpty()) {
92 log.warn(
93 "Ports on Switch {} should be removed prior to removing Switch. Removing Switch anyways",
94 swEvt);
95 // XXX Should we remove Port?
96 }
97 if (!sw.getDevices().isEmpty()) {
98 log.warn(
99 "Devices on Switch {} should be removed prior to removing Switch. Removing Switch anyways",
100 swEvt);
101 // XXX Should we remove Device to Switch relation?
102 }
103 if (!sw.getIncomingLinks().iterator().hasNext()) {
104 log.warn(
105 "IncomingLinks on Switch {} should be removed prior to removing Switch. Removing Switch anyways",
106 swEvt);
107 // XXX Should we remove Link?
108 }
109 if (!sw.getOutgoingLinks().iterator().hasNext()) {
110 log.warn(
111 "OutgoingLinks on Switch {} should be removed prior to removing Switch. Removing Switch anyways",
112 swEvt);
113 // XXX Should we remove Link?
114 }
115
116 boolean removed = switches.remove(swEvt.getDpid(), sw);
117 if (removed) {
118 log.warn(
119 "Switch instance was replaced concurrently while removing {}. Something is not right.",
120 sw);
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800121 }
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800122 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -0800123
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800124 /**
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800125 * put Port
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800126 *
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800127 * XXX Internal Invariant-maintenance method. Will not write to DB. Will not
128 * fire Notification.
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800129 *
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800130 * @param portEvt
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800131 */
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800132 void putPort(PortEvent portEvt) {
133 if (portEvt == null) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800134 throw new IllegalArgumentException("Port cannot be null");
135 }
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800136 Switch sw = switches.get(portEvt.getDpid());
137 if (sw == null) {
138 throw new BrokenInvariantException(String.format(
139 "Switch with dpid %s did not exist.",
140 new Dpid(portEvt.getDpid())));
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800141 }
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800142 Port p = sw.getPort(portEvt.getNumber());
143 PortImpl port = null;
144 if (p != null) {
145 port = getPortImpl(p);
146 }
147
148 if (port == null) {
149 port = new PortImpl(this, sw, portEvt.getNumber());
150 }
151
152 // TODO update attributes
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800153
154 SwitchImpl s = getSwitchImpl(sw);
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800155 s.addPort(port);
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800156 }
157
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800158 /**
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800159 * remove Port
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800160 *
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800161 * XXX Internal Invariant-maintenance method. Will not write to DB. Will not
162 * fire Notification.
163 *
164 * @param portEvt
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800165 */
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800166 void removePort(PortEvent portEvt) {
167 if (portEvt == null) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800168 throw new IllegalArgumentException("Port cannot be null");
169 }
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800170
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800171 Switch sw = switches.get(portEvt.getDpid());
172 if (sw == null) {
173 log.warn("Parent Switch for Port {} already removed, ignoreing", portEvt);
174 return;
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800175 }
176
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800177 Port p = sw.getPort(portEvt.getNumber());
178 if (p == null) {
179 log.warn("Port {} already removed, ignoreing", portEvt);
180 return;
181 }
182 // null check
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800183
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800184 if (!p.getDevices().iterator().hasNext()) {
185 log.warn(
186 "Devices on Port {} should be removed prior to removing Port. Removing Port anyways",
187 portEvt);
188 // XXX Should we remove Device to Port relation?
189 }
190 if (p.getIncomingLink() != null) {
191 log.warn(
192 "IncomingLinks on Port {} should be removed prior to removing Port. Removing Port anyways",
193 portEvt);
194 // XXX Should we remove Link?
195 }
196 if (p.getOutgoingLink() != null) {
197 log.warn(
198 "OutgoingLinks on Port {} should be removed prior to removing Port. Removing Port anyways",
199 portEvt);
200 // XXX Should we remove Link?
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800201 }
202
203 // remove Port from Switch
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800204 SwitchImpl s = getSwitchImpl(sw);
205 s.removePort(p);
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800206 }
207
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800208 /**
209 * put Link
210 *
211 * XXX Internal Invariant-maintenance method. Will not write to DB. Will not
212 * fire Notification.
213 *
214 * @param linkEvt
215 */
216 void putLink(LinkEvent linkEvt) {
217 if (linkEvt == null) {
218 throw new IllegalArgumentException("Link cannot be null");
219 }
220 // TODO Auto-generated method stub
221
222 Switch srcSw = switches.get(linkEvt.getSrc().dpid);
223 if (srcSw == null) {
224 throw new BrokenInvariantException(
225 String.format(
226 "Switch with dpid %s did not exist.",
227 new Dpid(linkEvt.getSrc().dpid)));
228 }
229
230 Switch dstSw = switches.get(linkEvt.getDst().dpid);
231 if (dstSw == null) {
232 throw new BrokenInvariantException(
233 String.format(
234 "Switch with dpid %s did not exist.",
235 new Dpid(linkEvt.getDst().dpid)));
236 }
237
238 Port srcPort = srcSw.getPort(linkEvt.getSrc().number);
239 if (srcPort == null) {
240 throw new BrokenInvariantException(
241 String.format(
242 "Src Port %s of a Link did not exist.",
243 linkEvt.getSrc() ));
244 }
245 Port dstPort = dstSw.getPort(linkEvt.getDst().number);
246 if (dstPort == null) {
247 throw new BrokenInvariantException(
248 String.format(
249 "Dst Port %s of a Link did not exist.",
250 linkEvt.getDst() ));
251 }
252
253 Link l = dstPort.getIncomingLink();
254 LinkImpl link = null;
255 assert( l == srcPort.getOutgoingLink() );
256 if (l != null) {
257// link = getLink
258 }
259
260 // TODO update Switch
261 // TODO update Link
262
263
264 // XXX check Existing Link first?
265// srcPort.setOutgoingLink(link);
266// dstPort.setIncomingLink(link);
267 }
268
269 /**
270 * removeLink
271 *
272 * XXX Internal Invariant-maintenance method. Will not write to DB. Will not
273 * fire Notification.
274 *
275 * @param link
276 */
277 void removeLink(LinkEvent link) {
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800278 if (link == null) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800279 throw new IllegalArgumentException("Link cannot be null");
280 }
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800281 // TODO Auto-generated method stub
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800282
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800283 // Switch srcSw = link.getSourceSwitch();
284 // if (!isSwitchInstanceInTopology(srcSw)) {
285 // // XXX Define or choose more appropriate Exception.
286 // throw new RuntimeException(
287 // String.format(
288 // "Switch with dpid %s did not exist or different instance registered.",
289 // new Dpid(srcSw.getDpid())));
290 // }
291 //
292 // Switch dstSw = link.getDestinationSwitch();
293 // if (!isSwitchInstanceInTopology(dstSw)) {
294 // // XXX Define or choose more appropriate Exception.
295 // throw new RuntimeException(
296 // String.format(
297 // "Switch with dpid %s did not exist or different instance registered.",
298 // new Dpid(dstSw.getDpid())));
299 // }
300 //
301 // PortImpl srcPort = getPortImpl(link.getSourcePort());
302 // PortImpl dstPort = getPortImpl(link.getDestinationPort());
303 //
304 // // XXX check Existing Link first?
305 // if (srcPort.getOutgoingLink() != link
306 // || dstPort.getIncomingLink() != link) {
307 // // XXX Define or choose more appropriate Exception.
308 // throw new RuntimeException(String.format(
309 // "Link %s did not belong to Topology", link.toString()));
310 // }
311 // // remove Link
312 // srcPort.setOutgoingLink(null);
313 // dstPort.setIncomingLink(null);
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800314 }
315
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800316 // XXX Need to rework Device related
317 /**
318 * Add new device to DB
319 *
320 * @param device
321 */
Yuta HIGUCHI0be4a662014-02-11 18:01:28 -0800322 void putDevice(DeviceEvent deviceEvt) {
323 if (deviceEvt == null) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800324 throw new IllegalArgumentException("Device cannot be null");
325 }
326 // TODO Auto-generated method stub
327
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800328 // Device existingDevice =
329 // getDeviceByMac(deviceToUpdate.getMacAddress());
330 // if (existingDevice != deviceToUpdate) {
331 // throw new IllegalArgumentException(
332 // "Must supply Device Object in this NetworkGraph");
333 // }
334 //
335 // DeviceImpl device = getDeviceImpl(deviceToUpdate);
336 //
337 // // Update IP Addr
338 // // uniq
339 // Set<InetAddress> prevAddrs = new HashSet<>(
340 // deviceToUpdate.getIpAddress());
341 // Set<InetAddress> newAddrs = updatedIpAddrs;
342 //
343 // // delta
344 // @SuppressWarnings("unchecked")
345 // Collection<InetAddress> delAddr = CollectionUtils.subtract(newAddrs,
346 // prevAddrs);
347 // @SuppressWarnings("unchecked")
348 // Collection<InetAddress> addAddr = CollectionUtils.subtract(prevAddrs,
349 // newAddrs);
350 //
351 // for (InetAddress addr : delAddr) {
352 // Set<Device> devices = addr2Device.get(addr);
353 // if (devices == null) {
354 // continue;
355 // }
356 // devices.remove(device);
357 // device.removeIpAddress(addr);
358 // }
359 // for (InetAddress addr : addAddr) {
360 // Set<Device> devices = addr2Device.get(addr);
361 // if (devices == null) {
362 // devices = new HashSet<>();
363 // addr2Device.put(addr, devices);
364 // }
365 // devices.add(device);
366 // device.addIpAddress(addr);
367 // }
368 //
369 // // Update Attachment Point
370 // // uniq
371 // Set<Port> prevPorts = new HashSet<>();
372 // CollectionUtils.addAll(prevAddrs,
373 // deviceToUpdate.getAttachmentPoints()
374 // .iterator());
375 // Set<Port> newPorts = updatedAttachmentPoints;
376 // // delta
377 // @SuppressWarnings("unchecked")
378 // Collection<Port> delPorts = CollectionUtils.subtract(newPorts,
379 // prevPorts);
380 // @SuppressWarnings("unchecked")
381 // Collection<Port> addPorts = CollectionUtils.subtract(prevPorts,
382 // newPorts);
383 //
384 // for (Port p : delPorts) {
385 // device.removeAttachmentPoint(p);
386 // getPortImpl(p).removeDevice(device);
387 // }
388 //
389 // for (Port p : addPorts) {
390 // device.addAttachmentPoint(p);
391 // getPortImpl(p).addDevice(device);
392 // }
393
394 // TODO Auto-generated method stub
395
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800396 }
397
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800398 void removeDevice(DeviceEvent device) {
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800399 if (device == null) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800400 throw new IllegalArgumentException("Device cannot be null");
401 }
402 // TODO Auto-generated method stub
403
404 }
405
406 private SwitchImpl getSwitchImpl(Switch sw) {
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800407 if (sw instanceof SwitchImpl) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800408 return (SwitchImpl) sw;
409 }
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800410 throw new ClassCastException("SwitchImpl expected, but found: " + sw);
411 }
412
413 private PortImpl getPortImpl(Port p) {
414 if (p instanceof PortImpl) {
415 return (PortImpl) p;
416 }
417 throw new ClassCastException("PortImpl expected, but found: " + p);
418 }
419
Yuta HIGUCHIc0366272014-02-10 21:04:57 -0800420 private DeviceImpl getDeviceImpl(Device d) {
421 if (d instanceof DeviceImpl) {
422 return (DeviceImpl) d;
423 }
424 throw new ClassCastException("DeviceImpl expected, but found: " + d);
425 }
426
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800427 public boolean isSwitchInstanceInTopology(Switch sw) {
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800428 // check if the sw instance is valid in Topology
429 if (sw != switches.get(sw.getDpid())) {
430 return false;
431 }
432 return true;
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800433 }
434
435 public void loadWholeTopologyFromDB() {
436 // XXX clear everything first?
437
438 for (RCSwitch sw : RCSwitch.getAllSwitches()) {
439 try {
440 sw.read();
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800441 // TODO if there is going to be inactive Switch in DB, skip
442 // TODO update other attributes if there exist any
443 putSwitch(new SwitchEvent(sw.getDpid()));
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800444 } catch (ObjectDoesntExistException e) {
445 log.error("Read Switch Failed, skipping", e);
446 }
447 }
448
449 for (RCPort p : RCPort.getAllPorts()) {
450 try {
451 p.read();
452
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800453 Switch sw = this.getSwitch(p.getDpid());
454 if (sw == null) {
455 log.error("Switch {} missing when adding Port {}",
456 new Dpid(p.getDpid()), p);
457 continue;
458 }
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800459 PortEvent portEvent = new PortEvent(p.getDpid(), p.getNumber());
460 // TODO update other attributes if there exist any
461 putPort(portEvent);
Yuta HIGUCHI765cd0d2014-02-06 12:46:41 -0800462 } catch (ObjectDoesntExistException e) {
463 log.error("Read Port Failed, skipping", e);
464 }
465 }
466
467 // TODO Is Device going to be in DB? If so, read from DB.
468 // for (RCDevice d : RCDevice.getAllDevices()) {
469 // try {
470 // d.read();
471 //
472 // } catch (ObjectDoesntExistException e) {
473 // log.debug("Read Device Failed, skipping", e);
474 // }
475 // }
476
477 for (RCLink l : RCLink.getAllLinks()) {
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800478 try {
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800479 l.read();
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800480
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800481 Switch srcSw = this.getSwitch(l.getSrc().dpid);
482 if (srcSw == null) {
483 log.error("Switch {} missing when adding Link {}",
484 new Dpid(l.getSrc().dpid), l);
485 continue;
486 }
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800487
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800488 Switch dstSw = this.getSwitch(l.getDst().dpid);
489 if (dstSw == null) {
490 log.error("Switch {} missing when adding Link {}",
491 new Dpid(l.getDst().dpid), l);
492 continue;
493 }
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800494
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800495 LinkEvent linkEvent = new LinkEvent(l.getSrc().dpid,
496 l.getSrc().number, l.getDst().dpid, l.getDst().number);
497 // TODO update other attributes if there exist any
498 putLink(linkEvent);
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800499 } catch (ObjectDoesntExistException e) {
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800500 log.debug("Delete Link Failed", e);
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800501 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800502 }
Yuta HIGUCHI80829d12014-02-05 20:16:56 -0800503 }
Yuta HIGUCHIcb951982014-02-11 13:31:44 -0800504
505 /**
506 * Exception to be thrown when Modification to the Network Graph cannot be continued due to broken invariant.
507 *
508 * XXX Should this be checked exception or RuntimeException
509 */
510 public static class BrokenInvariantException extends RuntimeException {
511 private static final long serialVersionUID = 1L;
512
513 public BrokenInvariantException() {
514 super();
515 }
516
517 public BrokenInvariantException(String message) {
518 super(message);
519 }
520 }
Jonathan Hart22eb9882014-02-11 15:52:59 -0800521
522 /* ******************************
523 * NetworkGraphDiscoveryInterface methods
524 * ******************************/
525
526 @Override
527 public void putSwitchEvent(SwitchEvent switchEvent) {
528 if (checkAddSwitchInvariant()) {
529 datastore.addSwitch(switchEvent);
530 putSwitch(switchEvent);
531 }
532 // TODO handle invariant violation
533 }
534
535 @Override
536 public void removeSwitchEvent(SwitchEvent switchEvent) {
537 if (checkRemoveSwitchInvariant()) {
538 datastore.deactivateSwitch(switchEvent);
539 removeSwitch(switchEvent);
540 }
541 // TODO handle invariant violation
542 }
543
544 @Override
545 public void putPortEvent(PortEvent portEvent) {
546 // TODO Auto-generated method stub
547
548 }
549
550 @Override
551 public void removePortEvent(PortEvent portEvent) {
552 // TODO Auto-generated method stub
553
554 }
555
556 @Override
557 public void putLinkEvent(LinkEvent linkEvent) {
558 if (checkAddLinkInvariant()) {
559 datastore.addLink(linkEvent);
560 putLink(linkEvent);
561 }
562 // TODO handle invariant violation
563 }
564
565 @Override
566 public void removeLinkEvent(LinkEvent linkEvent) {
567 if (checkRemoveLinkInvariant()) {
568 datastore.removeLink(linkEvent);
569 removeLink(linkEvent);
570 }
571 // TODO handle invariant violation
572 }
573
574 @Override
Yuta HIGUCHI0be4a662014-02-11 18:01:28 -0800575 public void putDeviceEvent(DeviceEvent device) {
Jonathan Hart22eb9882014-02-11 15:52:59 -0800576 // TODO Auto-generated method stub
577
578 }
579
580 @Override
581 public void removeDeviceEvent(DeviceEvent deviceEvent) {
582 // TODO Auto-generated method stub
583
584 }
585
586 /* *****************
587 * Internal methods to check invariants of the network graph
588 * *****************/
589
590 private boolean checkAddSwitchInvariant() {
591 // TODO implement
592 return true;
593 }
594
595 private boolean checkRemoveSwitchInvariant() {
596 // TODO implement
597 return true;
598 }
599
600 private boolean checkAddPortInvariant() {
601 // TODO implement
602 return true;
603 }
604
605 private boolean checkRemovePortInvariant() {
606 // TODO implement
607 return true;
608 }
609
610 private boolean checkAddLinkInvariant() {
611 // TODO implement
612 return true;
613 }
614
615 private boolean checkRemoveLinkInvariant() {
616 // TODO implement
617 return true;
618 }
619
620 private boolean checkAddDeviceInvariant() {
621 // TODO implement
622 return true;
623 }
624
625 private boolean checkRemoveDeviceInvariant() {
626 // TODO implement
627 return true;
628 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800629}