2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.topologymanager.internal;
11 import java.net.InetAddress;
12 import java.net.UnknownHostException;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.Iterator;
17 import java.util.List;
20 import java.util.concurrent.ConcurrentMap;
21 import org.junit.After;
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.controller.sal.core.Bandwidth;
26 import org.opendaylight.controller.sal.core.ConstructionException;
27 import org.opendaylight.controller.sal.core.Description;
28 import org.opendaylight.controller.sal.core.Edge;
29 import org.opendaylight.controller.sal.core.Host;
30 import org.opendaylight.controller.sal.core.Latency;
31 import org.opendaylight.controller.sal.core.Node;
32 import org.opendaylight.controller.sal.core.Node.NodeIDType;
33 import org.opendaylight.controller.sal.core.NodeConnector;
34 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
35 import org.opendaylight.controller.sal.core.Property;
36 import org.opendaylight.controller.sal.core.State;
37 import org.opendaylight.controller.sal.core.TimeStamp;
38 import org.opendaylight.controller.sal.core.UpdateType;
39 import org.opendaylight.controller.sal.packet.address.EthernetAddress;
40 import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
41 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
42 import org.opendaylight.controller.sal.utils.NodeCreator;
43 import org.opendaylight.controller.sal.utils.Status;
44 import org.opendaylight.controller.sal.utils.StatusCode;
45 import org.opendaylight.controller.switchmanager.ISwitchManager;
46 import org.opendaylight.controller.switchmanager.SpanConfig;
47 import org.opendaylight.controller.switchmanager.Subnet;
48 import org.opendaylight.controller.switchmanager.SubnetConfig;
49 import org.opendaylight.controller.switchmanager.Switch;
50 import org.opendaylight.controller.switchmanager.SwitchConfig;
51 import org.opendaylight.controller.topologymanager.TopologyUserLinkConfig;
53 public class TopologyManagerImplTest {
54 private TopologyManagerImpl topoManagerImpl;
57 * Mockup of switch manager that only maintains existence of node
60 private final class TestSwitchManager implements ISwitchManager {
61 private final Set<Node> nodeSet = new HashSet<Node>();
62 private final Set<NodeConnector> nodeConnectorSet =
63 new HashSet<NodeConnector>();
65 private void addNodeConnectors(NodeConnector ... connectors) {
66 for (NodeConnector nc: connectors) {
68 nodeSet.add(nc.getNode());
69 nodeConnectorSet.add(nc);
74 private void addNodeConnectors(TopologyUserLinkConfig ... links) {
75 for (TopologyUserLinkConfig link: links) {
77 NodeConnector.fromString(link.getSrcNodeConnector());
79 NodeConnector.fromString(link.getDstNodeConnector());
80 addNodeConnectors(src, dst);
84 private void clear() {
86 nodeConnectorSet.clear();
90 public Status addSubnet(SubnetConfig configObject) {
95 public Status removeSubnet(SubnetConfig configObject) {
100 public Status modifySubnet(SubnetConfig configObject) {
105 public Status removeSubnet(String name) {
110 public List<Switch> getNetworkDevices() {
115 public List<SubnetConfig> getSubnetsConfigList() {
120 public SubnetConfig getSubnetConfig(String subnet) {
125 public Subnet getSubnetByNetworkAddress(InetAddress networkAddress) {
130 public Status saveSwitchConfig() {
135 public Status addSpanConfig(SpanConfig configObject) {
140 public Status removeSpanConfig(SpanConfig cfgObject) {
145 public List<SpanConfig> getSpanConfigList() {
150 public List<NodeConnector> getSpanPorts(Node node) {
155 public void updateSwitchConfig(SwitchConfig cfgObject) {
159 public Status updateNodeConfig(SwitchConfig switchConfig) {
164 public Status removeNodeConfig(String nodeId) {
169 public SwitchConfig getSwitchConfig(String nodeId) {
174 public Status addPortsToSubnet(String name, List<String> nodeConnectors) {
179 public Status removePortsFromSubnet(String name, List<String> nodeConnectors) {
184 public Set<Node> getNodes() {
185 return new HashSet<Node>(nodeSet);
189 public Map<String, Property> getNodeProps(Node node) {
190 return new HashMap<String, Property>();
194 public Property getNodeProp(Node node, String propName) {
199 public void setNodeProp(Node node, Property prop) {
203 public Status removeNodeProp(Node node, String propName) {
208 public Status removeNodeAllProps(Node node) {
213 public Set<NodeConnector> getUpNodeConnectors(Node node) {
214 return getNodeConnectors(node);
218 public Set<NodeConnector> getNodeConnectors(Node node) {
219 Set<NodeConnector> set = new HashSet<NodeConnector>();
220 for (NodeConnector nc: nodeConnectorSet) {
221 if (nc.getNode().equals(node)) {
230 public Set<NodeConnector> getPhysicalNodeConnectors(Node node) {
231 return getNodeConnectors(node);
235 public Map<String, Property> getNodeConnectorProps(NodeConnector nodeConnector) {
236 return new HashMap<String, Property>();
240 public Property getNodeConnectorProp(NodeConnector nodeConnector, String propName) {
245 public Status addNodeConnectorProp(NodeConnector nodeConnector, Property prop) {
250 public Status removeNodeConnectorProp(NodeConnector nc, String propName) {
255 public Status removeNodeConnectorAllProps(NodeConnector nodeConnector) {
260 public NodeConnector getNodeConnector(Node node, String nodeConnectorName) {
265 public boolean isSpecial(NodeConnector p) {
266 String type = p.getType();
267 return (type.equals(NodeConnectorIDType.CONTROLLER)
268 || type.equals(NodeConnectorIDType.ALL)
269 || type.equals(NodeConnectorIDType.SWSTACK)
270 || type.equals(NodeConnectorIDType.HWPATH));
274 public Boolean isNodeConnectorEnabled(NodeConnector nodeConnector) {
275 if (doesNodeConnectorExist(nodeConnector)) {
278 return Boolean.FALSE;
282 public boolean doesNodeConnectorExist(NodeConnector nc) {
283 return (nc != null && nodeConnectorSet.contains(nc));
287 public byte[] getControllerMAC() {
292 public byte[] getNodeMAC(Node node) {
297 public Property createProperty(String propName, String propValue) {
302 public String getNodeDescription(Node node) {
307 public Status removeControllerProperty(String propertyName){
312 public Set<Switch> getConfiguredNotConnectedSwitches() {
313 // TODO Auto-generated method stub
318 public Map<String, Property> getControllerProperties() {
319 // TODO Auto-generated method stub
324 public Property getControllerProperty(String propertyName) {
325 // TODO Auto-generated method stub
330 public Status setControllerProperty(Property property) {
331 // TODO Auto-generated method stub
337 public void setUp() {
338 topoManagerImpl = new TopologyManagerImpl();
339 topoManagerImpl.startTest();
343 public void tearDown() {
344 if (topoManagerImpl != null) {
345 topoManagerImpl.stopTest();
346 topoManagerImpl = null;
351 * Sets the node, edges and properties for edges here: Edge <SwitchId :
352 * NodeConnectorId> : <1:1>--><11:11>; <1:2>--><11:12>; <3:3>--><13:13>;
353 * <3:4>--><13:14>; <5:5>--><15:15>; <5:6>--><15:16>; Method used by two
354 * tests: testGetNodeEdges and testGetEdges
356 * @param topoManagerImpl
358 * @throws ConstructionException
360 public void setNodeEdges(TopologyManagerImpl topoManagerImpl, TestSwitchManager swMgr)
361 throws ConstructionException {
362 topoManagerImpl.nonClusterObjectCreate();
368 Set<Property> props = new HashSet<Property>();
369 state = new State(State.EDGE_UP);
370 bw = new Bandwidth(Bandwidth.BW100Gbps);
371 l = new Latency(Latency.LATENCY100ns);
376 for (short i = 1; i < 6; i = (short) (i + 2)) {
377 List<TopoEdgeUpdate> topoedgeupdateList = new ArrayList<TopoEdgeUpdate>();
378 NodeConnector headnc1 = NodeConnectorCreator.createOFNodeConnector(
379 i, NodeCreator.createOFNode((long) i));
380 NodeConnector tailnc1 = NodeConnectorCreator
381 .createOFNodeConnector((short) (i + 10),
382 NodeCreator.createOFNode((long) (i + 10)));
383 swMgr.addNodeConnectors(tailnc1, headnc1);
384 Edge e1 = new Edge(tailnc1, headnc1);
385 TopoEdgeUpdate teu1 = new TopoEdgeUpdate(e1, props,
387 topoedgeupdateList.add(teu1);
389 NodeConnector tailnc2 = NodeConnectorCreator.createOFNodeConnector(
390 (short) (i + 1), headnc1.getNode());
391 NodeConnector headnc2 = NodeConnectorCreator.createOFNodeConnector(
392 (short) (i + 11), tailnc1.getNode());
393 swMgr.addNodeConnectors(tailnc1, headnc2);
394 Edge e2 = new Edge(tailnc2, headnc2);
395 TopoEdgeUpdate teu2 = new TopoEdgeUpdate(e2, props,
397 topoedgeupdateList.add(teu2);
398 topoManagerImpl.edgeUpdate(topoedgeupdateList);
401 Assert.assertTrue(topoManagerImpl.flushUpdateQueue(5000));
405 public void testGetNodeEdges() throws ConstructionException {
406 TestSwitchManager swMgr = new TestSwitchManager();
407 topoManagerImpl.setSwitchManager(swMgr);
408 setNodeEdges(topoManagerImpl, swMgr);
410 Map<Node, Set<Edge>> nodeEdgeMap = topoManagerImpl.getNodeEdges();
411 for (Iterator<Map.Entry<Node, Set<Edge>>> i = nodeEdgeMap.entrySet()
412 .iterator(); i.hasNext();) {
413 Map.Entry<Node, Set<Edge>> entry = i.next();
414 Node node = entry.getKey();
415 Long nodeId = ((Long) node.getID()).longValue();
416 Assert.assertTrue((node.getType().equals(NodeIDType.OPENFLOW)));
418 Set<Edge> edges = entry.getValue();
419 for (Edge edge : edges) {
420 Long headNcId = ((Short) edge.getHeadNodeConnector().getID())
422 Long tailNcId = ((Short) edge.getTailNodeConnector().getID())
425 (headNcId.equals(nodeId) && tailNcId.equals(nodeId + 10))
426 || (headNcId.equals(nodeId + 11) && tailNcId.equals(nodeId + 1))
427 || (headNcId.equals(nodeId + 1) && tailNcId.equals(nodeId - 9))
428 || (headNcId.equals(nodeId - 10) && tailNcId.equals(nodeId))
433 Assert.assertTrue(nodeEdgeMap.isEmpty());
437 public void testGetEdges() throws ConstructionException {
438 TestSwitchManager swMgr = new TestSwitchManager();
439 topoManagerImpl.setSwitchManager(swMgr);
440 setNodeEdges(topoManagerImpl, swMgr);
442 Map<Edge, Set<Property>> edgeProperty = topoManagerImpl.getEdges();
444 for (Iterator<Map.Entry<Edge, Set<Property>>> i = edgeProperty
445 .entrySet().iterator(); i.hasNext();) {
446 Map.Entry<Edge, Set<Property>> entry = i.next();
447 Edge e = entry.getKey();
448 NodeConnector headnc = e.getHeadNodeConnector();
449 NodeConnector tailnc = e.getTailNodeConnector();
451 Long headNodeId = (Long) headnc.getNode().getID();
453 Long headNcId = ((Short) headnc.getID()).longValue();
454 Long tailNcId = ((Short) tailnc.getID()).longValue();
456 if (headNodeId == 1 || headNodeId == 3 || headNodeId == 5) {
457 Assert.assertTrue((headNcId.equals(headNodeId) && tailNcId
458 .equals(headNodeId + 10))
459 || (headNcId.equals(headNodeId + 10) && tailNcId
461 || (headNcId.equals(headNodeId + 1) && tailNcId
462 .equals(headNodeId + 11))
463 || (headNcId.equals(headNodeId + 11) && tailNcId
464 .equals(headNodeId + 1)));
465 } else if (headNodeId == 11 || headNodeId == 13 || headNodeId == 15) {
466 Assert.assertTrue((headNcId.equals(headNodeId) && tailNcId
467 .equals(headNodeId - 10))
468 || (headNcId.equals(headNodeId) && tailNcId
469 .equals(headNodeId - 10))
470 || (headNcId.equals(headNodeId - 9) && tailNcId
471 .equals(headNodeId + 1))
472 || (headNcId.equals(headNodeId + 1) && tailNcId
473 .equals(headNodeId - 9)));
476 Set<Property> prop = entry.getValue();
477 for (Property p : prop) {
480 if (p instanceof Bandwidth) {
481 Bandwidth b = (Bandwidth) p;
482 pName = Bandwidth.BandwidthPropName;
483 pValue = b.getValue();
484 Assert.assertTrue(pName.equals(p.getName())
485 && pValue == Bandwidth.BW100Gbps);
488 if (p instanceof Latency) {
489 Latency l = (Latency) p;
490 pName = Latency.LatencyPropName;
491 pValue = l.getValue();
492 Assert.assertTrue(pName.equals(p.getName())
493 && pValue == Latency.LATENCY100ns);
496 if (p instanceof State) {
497 State state = (State) p;
498 pName = State.StatePropName;
499 pValue = state.getValue();
500 Assert.assertTrue(pName.equals(p.getName())
501 && pValue == State.EDGE_UP);
507 Assert.assertTrue(edgeProperty.isEmpty());
511 public void testAddDeleteUserLink() {
512 TopologyUserLinkConfig link1 = new TopologyUserLinkConfig("default1",
513 "OF|1@OF|2", "OF|1@OF|3");
514 TopologyUserLinkConfig link2 = new TopologyUserLinkConfig("default1",
515 "OF|10@OF|20", "OF|10@OF|30");
516 TopologyUserLinkConfig link3 = new TopologyUserLinkConfig("default2",
517 "OF|1@OF|2", "OF|1@OF|3");
518 TopologyUserLinkConfig link4 = new TopologyUserLinkConfig("default20",
519 "OF|10@OF|20", "OF|10@OF|30");
521 TestSwitchManager swMgr = new TestSwitchManager();
522 topoManagerImpl.setSwitchManager(swMgr);
523 topoManagerImpl.nonClusterObjectCreate();
525 swMgr.addNodeConnectors(link1, link2, link3, link4);
527 Assert.assertTrue(topoManagerImpl.addUserLink(link1).isSuccess());
528 Assert.assertTrue(topoManagerImpl.addUserLink(link2).getCode() == StatusCode.CONFLICT);
529 Assert.assertTrue(topoManagerImpl.addUserLink(link3).getCode() == StatusCode.CONFLICT);
530 Assert.assertTrue(topoManagerImpl.addUserLink(link4).isSuccess());
532 Assert.assertTrue(topoManagerImpl.deleteUserLink(null).getCode() == StatusCode.BADREQUEST);
533 Assert.assertTrue(topoManagerImpl.deleteUserLink(link1.getName())
535 Assert.assertTrue(topoManagerImpl.deleteUserLink(link4.getName())
537 Assert.assertTrue(topoManagerImpl.getUserLinks().isEmpty());
539 TopologyUserLinkConfig badlink1 =
540 new TopologyUserLinkConfig("bad1", "OF|1@OF|4", "OF|1@OF|5");
541 TopologyUserLinkConfig badlink2 =
542 new TopologyUserLinkConfig("bad2", "OF|10@OF|7", "OF|7@OF|13");
543 Assert.assertEquals(StatusCode.NOTFOUND,
544 topoManagerImpl.addUserLink(badlink1).getCode());
545 Assert.assertEquals(StatusCode.NOTFOUND,
546 topoManagerImpl.addUserLink(badlink2).getCode());
550 public void testGetUserLink() {
551 TopologyUserLinkConfig[] link = new TopologyUserLinkConfig[5];
552 TopologyUserLinkConfig[] reverseLink = new TopologyUserLinkConfig[5];
553 TestSwitchManager swMgr = new TestSwitchManager();
554 topoManagerImpl.setSwitchManager(swMgr);
555 topoManagerImpl.nonClusterObjectCreate();
557 String name = "Test";
558 String srcSwitchId = null;
559 String srcNodeConnectorIDType = null;
560 String srcPort = null;
561 String srcNodeIDType = null;
562 String dstNodeIDType = null;
563 String dstSwitchId = null;
564 String dstNodeConnectorIDType = null;
565 String dstPort = null;
566 String srcNodeConnector = null;
567 String dstNodeConnector = null;
569 /* Creating userlinks and checking for their validity */
570 link[0] = new TopologyUserLinkConfig(name, srcNodeConnector, dstNodeConnector);
571 Assert.assertTrue(link[0].isValid() == false);
573 srcNodeConnector = "OF|1@OF|1";
574 link[0] = new TopologyUserLinkConfig(name, srcNodeConnector, dstNodeConnector);
575 Assert.assertTrue(link[0].isValid() == false);
577 dstNodeConnector = "OF|1@OF|2";
578 link[0] = new TopologyUserLinkConfig(name, srcNodeConnector, dstNodeConnector);
579 Assert.assertTrue(link[0].isValid() == true);
583 for (i = 0; i < 5; i++) {
584 link[i] = new TopologyUserLinkConfig();
586 name = Integer.toString(i + 1);
587 srcSwitchId = Integer.toString(i + 1);
588 srcPort = Integer.toString(i + 1);
589 dstSwitchId = Integer.toString((i + 1) * 10);
590 dstPort = Integer.toString((i + 1) * 10);
592 link[i].setName(name);
593 srcNodeConnectorIDType = dstNodeConnectorIDType = "INCORRECT";
594 srcNodeConnector = srcNodeConnectorIDType+"|"+srcSwitchId+"@"+srcNodeConnectorIDType+"|"+srcPort;
595 dstNodeConnector = dstNodeConnectorIDType+"|"+dstSwitchId+"@"+dstNodeConnectorIDType+"|"+dstPort;
597 link[i].setSrcNodeConnector(srcNodeConnector);
598 Assert.assertTrue(link[i].isValid() == false);
600 srcNodeConnectorIDType = "OF";
601 srcNodeConnector = srcNodeConnectorIDType+"|"+srcSwitchId+"@"+srcNodeConnectorIDType+"|"+srcPort;
602 link[i].setSrcNodeConnector(srcNodeConnector);
603 Assert.assertTrue(link[i].isValid() == false);
605 dstNodeConnectorIDType = "OF";
606 dstNodeConnector = dstNodeConnectorIDType+"|"+dstSwitchId+"@"+dstNodeConnectorIDType+"|"+dstPort;
607 link[i].setDstNodeConnector(dstNodeConnector);
608 Assert.assertTrue(link[i].isValid() == true);
610 reverseLink[i] = new TopologyUserLinkConfig(name, dstNodeConnector, srcNodeConnector);
612 Assert.assertEquals(StatusCode.NOTFOUND,
613 topoManagerImpl.addUserLink(link[i]).getCode());
614 swMgr.addNodeConnectors(link[i]);
615 Assert.assertTrue(topoManagerImpl.addUserLink(link[i]).isSuccess());
618 ConcurrentMap<String, TopologyUserLinkConfig> userLinks = topoManagerImpl
620 TopologyUserLinkConfig resultLink;
622 for (i = 0; i < 5; i++) {
623 resultLink = userLinks.get(((Integer) (i + 1)).toString());
625 Assert.assertTrue(resultLink.getName().equals(
626 reverseLink[i].getName()));
627 Assert.assertTrue(resultLink.getDstNodeConnector().equals(
628 reverseLink[i].getSrcNodeConnector()));
629 Assert.assertTrue(resultLink.getSrcNodeConnector().equals(
630 reverseLink[i].getDstNodeConnector()));
635 public void testHostLinkMethods() throws ConstructionException,
636 UnknownHostException {
637 TestSwitchManager swMgr = new TestSwitchManager();
638 topoManagerImpl.setSwitchManager(swMgr);
639 topoManagerImpl.nonClusterObjectCreate();
645 Set<Property> props = new HashSet<Property>();
646 state = new State(State.EDGE_UP);
647 bw = new Bandwidth(Bandwidth.BW100Gbps);
648 l = new Latency(Latency.LATENCY100ns);
655 Host[] h = new Host[5];
656 NodeConnector[] nc = new NodeConnector[5];
659 * Adding host, nodeConnector to hostsDB for the i = 0,1,2,3. No host
662 for (int i = 0; i < 5; i++) {
663 if (hostCounter < 4) {
664 ea = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
665 (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) i });
666 String stringIP = new StringBuilder().append(i + 1).append(".")
667 .append(i + 10).append(".").append(i + 20).append(".")
668 .append(i + 30).toString();
669 ip = InetAddress.getByName(stringIP);
670 h[hostCounter] = new Host(ea, ip);
672 h[hostCounter] = null;
675 nc[i] = NodeConnectorCreator.createOFNodeConnector((short) (i + 1),
676 NodeCreator.createOFNode((long) (i + 1)));
678 .updateHostLink(nc[i], h[i], UpdateType.ADDED, props);
681 for (int i = 0; i < 5; i++) {
682 Host host = topoManagerImpl.getHostAttachedToNodeConnector(nc[i]);
684 Assert.assertTrue(host == null);
686 Assert.assertTrue(host.equals(h[i]));
690 Set<NodeConnector> ncSet = topoManagerImpl.getNodeConnectorWithHost();
691 for (int i = 0; i < 5; i++) {
692 Assert.assertTrue(ncSet.remove(nc[i]));
694 Assert.assertTrue(ncSet.isEmpty());
698 public void testGetNodesWithNodeConnectorHost()
699 throws ConstructionException, UnknownHostException {
700 TestSwitchManager swMgr = new TestSwitchManager();
701 topoManagerImpl.setSwitchManager(swMgr);
702 topoManagerImpl.nonClusterObjectCreate();
708 Set<Property> props = new HashSet<Property>();
709 state = new State(State.EDGE_UP);
710 bw = new Bandwidth(Bandwidth.BW100Gbps);
711 l = new Latency(Latency.LATENCY100ns);
718 Host[] h = new Host[5];
719 NodeConnector[] nc = new NodeConnector[5];
722 * Adding host, nodeconnector, properties of edge to hostsDB for the
723 * first three nodes only
725 for (int i = 1; i < 6; i++) {
727 ea = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
728 (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) i });
729 String stringIP = new StringBuilder().append(i).append(".")
730 .append(i + 10).append(".").append(i + 20).append(".")
731 .append(i + 30).toString();
732 ip = InetAddress.getByName(stringIP);
733 h[hostCounter] = new Host(ea, ip);
735 h[hostCounter] = null;
738 nc[i - 1] = NodeConnectorCreator.createOFNodeConnector((short) i,
739 NodeCreator.createOFNode((long) i));
740 topoManagerImpl.updateHostLink(nc[i - 1], h[i - 1],
741 UpdateType.ADDED, props);
744 /* Get the nodes which have host connected to its nodeConnector */
745 Map<Node, Set<NodeConnector>> nodeNCmap = topoManagerImpl
746 .getNodesWithNodeConnectorHost();
747 for (int i = 1; i < 6; i++) {
748 Node node = nc[i - 1].getNode();
749 Set<NodeConnector> ncSet = nodeNCmap.get(nc[i - 1].getNode());
751 Assert.assertTrue(ncSet == nodeNCmap.remove(node));
754 Assert.assertTrue(nodeNCmap.isEmpty());
758 public void bug1348FixTest() throws ConstructionException,
759 InterruptedException {
760 TestSwitchManager swMgr = new TestSwitchManager();
761 topoManagerImpl.setSwitchManager(swMgr);
762 topoManagerImpl.nonClusterObjectCreate();
764 NodeConnector headnc1 = NodeConnectorCreator.createOFNodeConnector(
765 (short) 1, NodeCreator.createOFNode(1000L));
766 NodeConnector tailnc1 = NodeConnectorCreator.createOFNodeConnector(
767 (short) 2, NodeCreator.createOFNode(2000L));
768 Edge edge = new Edge(headnc1, tailnc1);
769 List<TopoEdgeUpdate> updatedEdges = new ArrayList<>();
770 Set<Property> edgeProps = new HashSet<>();
771 edgeProps.add(new TimeStamp(System.currentTimeMillis(), "creation"));
772 edgeProps.add(new Latency(Latency.LATENCY100ns));
773 edgeProps.add(new State(State.EDGE_UP));
774 edgeProps.add(new Bandwidth(Bandwidth.BW100Gbps));
775 edgeProps.add(new Description("Test edge"));
776 updatedEdges.add(new TopoEdgeUpdate(edge, edgeProps, UpdateType.CHANGED));
779 topoManagerImpl.edgeUpdate(updatedEdges);
780 } catch (Exception e) {
781 Assert.fail("Exception was raised when trying to update edge properties: " + e.getMessage());
784 Assert.assertTrue(topoManagerImpl.flushUpdateQueue(5000));
786 Assert.assertNotNull(topoManagerImpl.getEdges().get(edge));
789 private void verifyEdgesSize(int expSize) throws InterruptedException {
791 for(int i = 0; i < timeout / 50; i++) {
792 if(topoManagerImpl.getEdges().size() == expSize) {
799 Assert.fail(String.format("Expected edges size %d. Actual was %d",
800 topoManagerImpl.getEdges().size(), expSize));
804 public void testNotifyNodeConnector() throws Exception {
805 TestSwitchManager swMgr = new TestSwitchManager();
806 topoManagerImpl.setSwitchManager(swMgr);
807 topoManagerImpl.nonClusterObjectCreate();
809 // Test NodeConnector notification in the case that there are no
810 // related edge updates.
811 NodeConnector nc1 = NodeConnectorCreator.createOFNodeConnector(
812 (short) 1, NodeCreator.createOFNode(1000L));
813 Map<String, Property> propMap = new HashMap<>();
814 swMgr.addNodeConnectors(nc1);
815 topoManagerImpl.notifyNodeConnector(nc1, UpdateType.ADDED, propMap);
818 topoManagerImpl.notifyNodeConnector(nc1, UpdateType.CHANGED, propMap);
822 topoManagerImpl.notifyNodeConnector(nc1, UpdateType.REMOVED, propMap);
825 // Test NodeConnector notification in the case that there is a related
826 // edge update just before the notification.
827 NodeConnector nc2 = NodeConnectorCreator.createOFNodeConnector(
828 (short) 2, NodeCreator.createOFNode(2000L));
829 Edge edge1 = new Edge(nc1, nc2);
830 Edge edge2 = new Edge(nc2, nc1);
831 Set<Property> props = new HashSet<Property>();
832 TopoEdgeUpdate teu1 = new TopoEdgeUpdate(edge1, props, UpdateType.ADDED);
833 TopoEdgeUpdate teu2 = new TopoEdgeUpdate(edge2, props, UpdateType.ADDED);
834 List<TopoEdgeUpdate> topoedgeupdateList = new ArrayList<TopoEdgeUpdate>();
835 topoedgeupdateList.add(teu1);
836 topoedgeupdateList.add(teu2);
837 topoManagerImpl.edgeUpdate(topoedgeupdateList);
838 swMgr.addNodeConnectors(nc1);
839 topoManagerImpl.notifyNodeConnector(nc1, UpdateType.ADDED, propMap);
840 swMgr.addNodeConnectors(nc2);
841 topoManagerImpl.notifyNodeConnector(nc2, UpdateType.CHANGED, propMap);
842 Assert.assertTrue(topoManagerImpl.flushUpdateQueue(5000));
845 teu1 = new TopoEdgeUpdate(edge1, props, UpdateType.REMOVED);
846 teu2 = new TopoEdgeUpdate(edge2, props, UpdateType.REMOVED);
847 topoedgeupdateList = new ArrayList<TopoEdgeUpdate>();
848 topoedgeupdateList.add(teu1);
849 topoedgeupdateList.add(teu2);
850 topoManagerImpl.edgeUpdate(topoedgeupdateList);
851 Assert.assertTrue(topoManagerImpl.flushUpdateQueue(5000));
853 topoManagerImpl.notifyNodeConnector(nc1, UpdateType.REMOVED, propMap);
854 topoManagerImpl.notifyNodeConnector(nc2, UpdateType.REMOVED, propMap);
858 // Test NodeConnector notification in the case that there are multiple
859 // edge updates related to the NodeConnector just before the notification.
860 teu1 = new TopoEdgeUpdate(edge1, props, UpdateType.ADDED);
861 teu2 = new TopoEdgeUpdate(edge2, props, UpdateType.ADDED);
862 TopoEdgeUpdate teu3 = new TopoEdgeUpdate(edge1, props, UpdateType.CHANGED);
863 TopoEdgeUpdate teu4 = new TopoEdgeUpdate(edge2, props, UpdateType.CHANGED);
864 TopoEdgeUpdate teu5 = new TopoEdgeUpdate(edge1, props, UpdateType.REMOVED);
865 TopoEdgeUpdate teu6 = new TopoEdgeUpdate(edge2, props, UpdateType.REMOVED);
866 topoedgeupdateList = new ArrayList<TopoEdgeUpdate>();
867 topoedgeupdateList.add(teu1);
868 topoedgeupdateList.add(teu2);
869 topoedgeupdateList.add(teu3);
870 topoedgeupdateList.add(teu4);
871 topoedgeupdateList.add(teu5);
872 topoedgeupdateList.add(teu6);
873 topoManagerImpl.edgeUpdate(topoedgeupdateList);
874 swMgr.addNodeConnectors(nc1);
875 topoManagerImpl.notifyNodeConnector(nc1, UpdateType.ADDED, propMap);
876 swMgr.addNodeConnectors(nc2);
877 topoManagerImpl.notifyNodeConnector(nc2, UpdateType.CHANGED, propMap);
878 Assert.assertTrue(topoManagerImpl.flushUpdateQueue(5000));
880 topoManagerImpl.notifyNodeConnector(nc1, UpdateType.REMOVED, propMap);
881 topoManagerImpl.notifyNodeConnector(nc2, UpdateType.REMOVED, propMap);
882 Assert.assertTrue(topoManagerImpl.flushUpdateQueue(5000));