weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology; |
| 2 | |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 3 | import static org.junit.Assert.*; |
| 4 | import static org.hamcrest.Matchers.*; |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 5 | |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 6 | import java.util.Collection; |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 7 | import java.util.Iterator; |
| 8 | |
| 9 | import net.floodlightcontroller.util.MACAddress; |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 10 | import net.onrc.onos.core.util.Dpid; |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 11 | import net.onrc.onos.core.util.LinkTuple; |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 12 | import net.onrc.onos.core.util.PortNumber; |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 13 | import net.onrc.onos.core.util.SwitchPort; |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 14 | |
| 15 | import org.junit.After; |
| 16 | import org.junit.Before; |
| 17 | import org.junit.Test; |
| 18 | |
| 19 | /** |
| 20 | * Unit tests for the TopologyImpl Class in the Topology module. |
| 21 | * These test cases check the sanity of getSwitch/removeSwitch, |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 22 | * getLink/removeLink, getHost/removeHost, and getPort functions and verify |
| 23 | * the data objects inside the global graphDB through a injected network. |
| 24 | * The injected network has a ring topology with a large number of switches |
| 25 | * (configurable), andeach switch is associated with one host and connected to |
| 26 | * two other switches. |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 27 | */ |
| 28 | public class TopologyImplTest { |
| 29 | private TopologyImpl testTopology; |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 30 | private static final int SWITCH_HOST_PORT = 1; |
| 31 | private static final PortNumber PORT_NUMBER_HOST = |
| 32 | PortNumber.uint32(SWITCH_HOST_PORT); |
| 33 | private static final int SWITCH_PORT_1 = 2; |
| 34 | private static final PortNumber PORT_NUMBER_1 = |
| 35 | PortNumber.uint32(SWITCH_PORT_1); |
| 36 | private static final int SWITCH_PORT_2 = 3; |
| 37 | private static final PortNumber PORT_NUMBER_2 = |
| 38 | PortNumber.uint32(SWITCH_PORT_2); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 39 | |
| 40 | // Set the test network size, it should be larger than 3 |
| 41 | private static final long TEST_SWITCH_NUM = 100L; |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 42 | private static final long TEST_HOST_NUM = TEST_SWITCH_NUM; |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 43 | |
| 44 | @Before |
| 45 | public void setUp() throws Exception { |
| 46 | // Create the injected network first |
| 47 | testTopology = new TopologyImpl(); |
| 48 | |
| 49 | // Create a number of switches and install two ports for each switch |
| 50 | for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) { |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 51 | final Dpid dpid = new Dpid(switchID); |
| 52 | SwitchEvent testSwitch = new SwitchEvent(dpid); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 53 | testTopology.putSwitch(testSwitch); |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 54 | testTopology.putPort(new PortEvent(dpid, PORT_NUMBER_1)); |
| 55 | testTopology.putPort(new PortEvent(dpid, PORT_NUMBER_2)); |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 56 | PortEvent hostPort = new PortEvent(dpid, PORT_NUMBER_HOST); |
Yuta HIGUCHI | e2a4e17 | 2014-07-03 10:50:39 -0700 | [diff] [blame] | 57 | testTopology.putPort(hostPort); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 58 | |
| 59 | // Create a host for each switch |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 60 | MACAddress hostMac = MACAddress.valueOf(switchID); |
| 61 | HostEvent testHost = new HostEvent(hostMac); |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 62 | testHost.addAttachmentPoint(hostPort.getSwitchPort()); |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 63 | testTopology.putHost(testHost); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 66 | // |
| 67 | // Create one bidirectional link b/w two switches to construct a ring |
| 68 | // topology. |
| 69 | // |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 70 | for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) { |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 71 | final Dpid dpidA = new Dpid(switchID); |
| 72 | final Dpid dpidB = new Dpid(switchID % TEST_SWITCH_NUM + 1); |
| 73 | LinkEvent testLinkEast = new LinkEvent( |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 74 | testTopology.getPort(dpidA, PORT_NUMBER_2).getSwitchPort(), |
| 75 | testTopology.getPort(dpidB, PORT_NUMBER_1).getSwitchPort() |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 76 | ); |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 77 | LinkEvent testLinkWest = new LinkEvent( |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 78 | testTopology.getPort(dpidB, PORT_NUMBER_1).getSwitchPort(), |
| 79 | testTopology.getPort(dpidA, PORT_NUMBER_2).getSwitchPort() |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 80 | ); |
| 81 | testTopology.putLink(testLinkEast); |
| 82 | testTopology.putLink(testLinkWest); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | @After |
| 87 | public void tearDown() throws Exception { |
| 88 | |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Test the result of getSwitch function. |
| 93 | */ |
| 94 | @Test |
| 95 | public void testGetSwitch() { |
| 96 | // Verify the switch is in the graphDB |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 97 | assertNotNull(testTopology.getSwitch(new Dpid(TEST_SWITCH_NUM - 1))); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 98 | |
| 99 | // Verify there is no such switch in the graphDB |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 100 | assertNull(testTopology.getSwitch(new Dpid(TEST_SWITCH_NUM + 1))); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 101 | long index = 0; |
| 102 | Iterator<Switch> itr = testTopology.getSwitches().iterator(); |
| 103 | while (itr.hasNext()) { |
| 104 | index++; |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 105 | Dpid swID = itr.next().getDpid(); |
| 106 | assertThat(swID.value(), |
| 107 | is(both(greaterThanOrEqualTo(1L)) |
| 108 | .and(lessThanOrEqualTo(TEST_SWITCH_NUM)))); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | // Verify the total number of switches |
| 112 | assertEquals(TEST_SWITCH_NUM, index); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Test the result of getPort function. |
| 117 | */ |
| 118 | @Test |
| 119 | public void testGetPort() { |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 120 | PortNumber bogusPortNum = PortNumber.uint32(SWITCH_PORT_2 + 1); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 121 | for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) { |
| 122 | // Verify ports are in the graphDB |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 123 | final Dpid dpid = new Dpid(switchID); |
| 124 | assertNotNull(testTopology.getSwitch(dpid).getPort(PORT_NUMBER_1)); |
| 125 | assertNotNull(testTopology.getSwitch(dpid).getPort(PORT_NUMBER_2)); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 126 | |
| 127 | // Verify there is no such port in the graphDB |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 128 | assertNull(testTopology.getSwitch(dpid).getPort(bogusPortNum)); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Test the result of getLink function. |
| 134 | */ |
| 135 | @Test |
| 136 | public void testGetLink() { |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 137 | Dpid sw1ID = new Dpid(1L); |
| 138 | Dpid sw3ID = new Dpid(3L); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 139 | |
| 140 | // Verify there is no such link b/w these two switches |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 141 | assertNull((testTopology.getSwitch(sw1ID)).getLinkToNeighbor(sw3ID)); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 142 | long index = 0; |
| 143 | Iterator<Link> itr = testTopology.getLinks().iterator(); |
| 144 | while (itr.hasNext()) { |
| 145 | index++; |
| 146 | Link objectLink = itr.next(); |
| 147 | Switch srcSw = (objectLink.getSrcSwitch()); |
| 148 | Switch dstSw = (objectLink.getDstSwitch()); |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 149 | |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 150 | LinkTuple linkId = objectLink.getLinkTuple(); |
| 151 | // Verify the link through #getLink |
| 152 | Link linkA = testTopology.getLink(linkId.getSrc().getDpid(), |
| 153 | linkId.getSrc().getPortNumber(), |
| 154 | linkId.getDst().getDpid(), |
| 155 | linkId.getDst().getPortNumber()); |
| 156 | assertEquals(linkId, linkA.getLinkTuple()); |
| 157 | |
| 158 | Link linkB = testTopology.getLink(linkId.getSrc().getDpid(), |
| 159 | linkId.getSrc().getPortNumber(), |
| 160 | linkId.getDst().getDpid(), |
| 161 | linkId.getDst().getPortNumber(), |
| 162 | TopologyElement.TYPE_PACKET_LAYER); |
| 163 | assertEquals(linkId, linkB.getLinkTuple()); |
| 164 | |
| 165 | |
| 166 | |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 167 | // Confirm the link is formed properly |
| 168 | final long smallerDpid = Math.min(srcSw.getDpid().value(), |
| 169 | dstSw.getDpid().value()); |
| 170 | final long largerDpid = Math.max(srcSw.getDpid().value(), |
| 171 | dstSw.getDpid().value()); |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 172 | assertThat(largerDpid - smallerDpid, |
| 173 | is(either(equalTo(1L)).or(equalTo(TEST_SWITCH_NUM - 1)))); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | // Verify the total number of links |
| 177 | assertEquals(TEST_SWITCH_NUM * 2, index); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Test the result of getOutgoingLink function. |
| 182 | */ |
| 183 | @Test |
| 184 | public void testGetOutgoingLink() { |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 185 | PortNumber bogusPortNum = PortNumber.uint32(SWITCH_PORT_2 + 1); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 186 | for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) { |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 187 | final Dpid dpid = new Dpid(switchID); |
| 188 | assertNotNull(testTopology.getOutgoingLink(dpid, PORT_NUMBER_1)); |
| 189 | assertNotNull(testTopology.getOutgoingLink(dpid, PORT_NUMBER_2)); |
| 190 | |
| 191 | Link la = testTopology.getOutgoingLink(dpid, PORT_NUMBER_2, |
| 192 | TopologyElement.TYPE_PACKET_LAYER); |
| 193 | Link lb = testTopology.getOutgoingLink(dpid, PORT_NUMBER_2); |
| 194 | |
| 195 | assertTrue(la.getLinkTuple().equals(lb.getLinkTuple())); |
| 196 | |
| 197 | Collection<Link> links = testTopology.getOutgoingLinks( |
| 198 | new SwitchPort(dpid, PORT_NUMBER_1)); |
| 199 | assertEquals(1, links.size()); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 200 | |
| 201 | // Verify there is no such link in the graphDB |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 202 | assertNull(testTopology.getOutgoingLink(dpid, bogusPortNum)); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Test the result of getIncomingLink function. |
| 208 | */ |
| 209 | @Test |
| 210 | public void testGetIncomingLink() { |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 211 | PortNumber bogusPortNum = PortNumber.uint32(SWITCH_PORT_2 + 1); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 212 | for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) { |
| 213 | // Verify the links are in the graphDB |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 214 | final Dpid dpid = new Dpid(switchID); |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 215 | assertNotNull(testTopology.getIncomingLink( |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 216 | dpid, PORT_NUMBER_1)); |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 217 | assertNotNull(testTopology.getIncomingLink( |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 218 | dpid, PORT_NUMBER_2)); |
| 219 | |
| 220 | Link la = testTopology.getIncomingLink(dpid, PORT_NUMBER_2, |
| 221 | TopologyElement.TYPE_PACKET_LAYER); |
| 222 | Link lb = testTopology.getIncomingLink(dpid, PORT_NUMBER_2); |
| 223 | |
| 224 | assertTrue(la.getLinkTuple().equals(lb.getLinkTuple())); |
| 225 | |
| 226 | Collection<Link> links = testTopology.getIncomingLinks( |
| 227 | new SwitchPort(dpid, PORT_NUMBER_1)); |
| 228 | assertEquals(1, links.size()); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 229 | |
| 230 | // Verify there is no such link in the graphDB |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 231 | assertNull(testTopology.getIncomingLink( |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 232 | dpid, bogusPortNum)); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | /** |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 237 | * Test the result of getHostByMac function. |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 238 | */ |
| 239 | @Test |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 240 | public void testGetHostByMac() { |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 241 | for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) { |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 242 | MACAddress hostMac = MACAddress.valueOf(switchID); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 243 | |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 244 | // Verify the host is in the graphDB |
| 245 | assertNotNull(testTopology.getHostByMac(hostMac)); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
| 249 | /** |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 250 | * Test the result of removeHost function. |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 251 | */ |
| 252 | @Test |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 253 | public void testRemoveHost() { |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 254 | int hostCount = 0; |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 255 | Iterator<Host> itr = testTopology.getHosts().iterator(); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 256 | while (itr.hasNext()) { |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 257 | Host currHost = itr.next(); |
| 258 | final MACAddress mac = currHost.getMacAddress(); |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 259 | testTopology.removeHost(mac); |
| 260 | assertNull(testTopology.getHostByMac(mac)); |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 261 | hostCount++; |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 262 | } |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 263 | for (Switch sw : testTopology.getSwitches()) { |
| 264 | for (Port port : sw.getPorts()) { |
| 265 | assertTrue(port.getHosts().isEmpty()); |
| 266 | } |
| 267 | } |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 268 | |
| 269 | // Verify all hosts have been removed successfully |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 270 | assertEquals(TEST_HOST_NUM, hostCount); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Test the result of removeLink function. |
| 275 | */ |
| 276 | @Test |
| 277 | public void testRemoveLink() { |
| 278 | long index = 0; |
| 279 | Iterator<Link> itr = testTopology.getLinks().iterator(); |
| 280 | while (itr.hasNext()) { |
| 281 | index++; |
| 282 | Link objectLink = itr.next(); |
| 283 | Switch srcSw = (objectLink.getSrcSwitch()); |
| 284 | Port srcPort = objectLink.getSrcPort(); |
| 285 | Switch dstSw = (objectLink.getDstSwitch()); |
| 286 | Port dstPort = objectLink.getDstPort(); |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 287 | |
| 288 | testTopology.removeLink(objectLink.getLinkTuple()); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 289 | |
| 290 | // Verify the link was removed successfully |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 291 | assertNull(testTopology.getLink( |
| 292 | srcSw.getDpid(), srcPort.getNumber(), |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 293 | dstSw.getDpid(), dstPort.getNumber())); |
| 294 | } |
| 295 | |
| 296 | // Verify all links have been removed successfully |
| 297 | assertEquals(TEST_SWITCH_NUM * 2, index); |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Test the result of removeSwitch function. |
| 302 | */ |
| 303 | @Test |
| 304 | public void testRemoveSwitch() { |
| 305 | for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) { |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 306 | final Dpid dpid = new Dpid(switchID); |
Pavlin Radoslavov | efa17b2 | 2014-08-01 16:57:56 -0700 | [diff] [blame] | 307 | Iterator<Host> itr = |
| 308 | testTopology.getSwitch(dpid).getHosts().iterator(); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 309 | while (itr.hasNext()) { |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 310 | testTopology.removeHost(itr.next().getMacAddress()); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 311 | } |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 312 | for (Port port : testTopology.getSwitch(dpid).getPorts()) { |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 313 | testTopology.removePort(port.getSwitchPort()); |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 314 | } |
| 315 | testTopology.removeSwitch(dpid); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 316 | |
| 317 | // Verify the switch has been removed from the graphDB successfully |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 318 | assertNull(testTopology.getSwitch(dpid)); |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | // Verify all switches have been removed successfully |
| 322 | Iterator<Switch> itr = testTopology.getSwitches().iterator(); |
| 323 | assertFalse(itr.hasNext()); |
| 324 | } |
Praseed Balakrishnan | 6f29f3e | 2014-07-10 10:16:31 -0700 | [diff] [blame] | 325 | |
| 326 | /** |
| 327 | * Tests the packet optical topology. |
| 328 | * Verify packet port having multiple links. Packet Port at packet layer |
| 329 | * has a link to another |
| 330 | * packet port and is also physically connected to a T-Port in optical |
| 331 | * later. |
| 332 | */ |
| 333 | @Test |
| 334 | public void testPacketOpticalTopology() { |
| 335 | MockPacketOpticalTopology mockPacketOpticalTopology = new |
| 336 | MockPacketOpticalTopology(); |
| 337 | mockPacketOpticalTopology.createSamplePacketOpticalTopology1(); |
| 338 | for (Switch sw : mockPacketOpticalTopology.getSwitches()) { |
| 339 | if (sw.getType().equals(TopologyElement.TYPE_PACKET_LAYER)) { |
| 340 | Collection<Port> ports = sw.getPorts(); |
| 341 | for (Port port : ports) { |
| 342 | if (port.getType().equals(TopologyElement |
| 343 | .TYPE_PACKET_LAYER)) { |
| 344 | if (!port.getOutgoingLinks().isEmpty()) { |
| 345 | assertEquals(2, port.getOutgoingLinks().size()); |
| 346 | } else if (!port.getIncomingLinks().isEmpty()) { |
| 347 | assertEquals(2, port.getIncomingLinks().size()); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | } |
weibit | d503707 | 2014-06-13 10:07:01 -0700 | [diff] [blame] | 354 | } |