Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.topology; |
| 2 | |
| 3 | import net.floodlightcontroller.core.IFloodlightProviderService; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 4 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 5 | import net.floodlightcontroller.core.test.MockThreadPoolService; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 6 | import net.floodlightcontroller.test.FloodlightTestCase; |
| 7 | import net.floodlightcontroller.threadpool.IThreadPoolService; |
HIGUCHI Yuta | a56fbde | 2013-06-17 14:26:05 -0700 | [diff] [blame] | 8 | import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 9 | |
| 10 | import org.junit.Before; |
| 11 | import org.junit.Test; |
| 12 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; |
| 14 | |
| 15 | public class TopologyManagerTest extends FloodlightTestCase { |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 16 | protected final static Logger log = LoggerFactory.getLogger(TopologyManagerTest.class); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 17 | TopologyManager tm; |
| 18 | FloodlightModuleContext fmc; |
| 19 | |
| 20 | @Before |
| 21 | public void setUp() throws Exception { |
| 22 | super.setUp(); |
| 23 | fmc = new FloodlightModuleContext(); |
| 24 | fmc.addService(IFloodlightProviderService.class, getMockFloodlightProvider()); |
| 25 | MockThreadPoolService tp = new MockThreadPoolService(); |
| 26 | fmc.addService(IThreadPoolService.class, tp); |
| 27 | tm = new TopologyManager(); |
| 28 | tp.init(fmc); |
| 29 | tm.init(fmc); |
| 30 | tp.startUp(fmc); |
| 31 | } |
| 32 | |
| 33 | @Test |
| 34 | public void testBasic1() throws Exception { |
| 35 | tm.addOrUpdateLink((long)1, (short)1, (long)2, (short)1, ILinkDiscovery.LinkType.DIRECT_LINK); |
| 36 | assertTrue(tm.getSwitchPorts().size() == 2); // for two nodes. |
| 37 | assertTrue(tm.getSwitchPorts().get((long)1).size()==1); |
| 38 | assertTrue(tm.getSwitchPorts().get((long)2).size()==1); |
| 39 | assertTrue(tm.getSwitchPortLinks().size()==2); |
| 40 | assertTrue(tm.getPortBroadcastDomainLinks().size()==0); |
| 41 | assertTrue(tm.getTunnelPorts().size()==0); |
| 42 | |
| 43 | tm.addOrUpdateLink((long)1, (short)2, (long)2, (short)2, ILinkDiscovery.LinkType.MULTIHOP_LINK); |
| 44 | assertTrue(tm.getSwitchPorts().size() == 2); // for two nodes. |
| 45 | assertTrue(tm.getSwitchPorts().get((long)1).size()==2); |
| 46 | assertTrue(tm.getSwitchPorts().get((long)2).size()==2); |
| 47 | assertTrue(tm.getSwitchPortLinks().size()==4); |
| 48 | assertTrue(tm.getPortBroadcastDomainLinks().size()==2); |
| 49 | assertTrue(tm.getTunnelPorts().size()==0); |
| 50 | |
| 51 | tm.addOrUpdateLink((long)1, (short)3, (long)2, (short)3, ILinkDiscovery.LinkType.TUNNEL); |
| 52 | assertTrue(tm.getSwitchPorts().size() == 2); // for two nodes. |
| 53 | assertTrue(tm.getSwitchPorts().get((long)1).size()==3); |
| 54 | assertTrue(tm.getSwitchPorts().get((long)2).size()==3); |
| 55 | assertTrue(tm.getSwitchPortLinks().size()==6); |
| 56 | assertTrue(tm.getPortBroadcastDomainLinks().size()==2); |
| 57 | assertTrue(tm.getTunnelPorts().size()==2); |
| 58 | |
| 59 | tm.removeLink((long)1, (short)2, (long)2, (short)2); |
| 60 | log.info("# of switchports. {}", tm.getSwitchPorts().get((long)1).size()); |
| 61 | assertTrue(tm.getSwitchPorts().get((long)1).size()==2); |
| 62 | assertTrue(tm.getSwitchPorts().get((long)2).size()==2); |
| 63 | assertTrue(tm.getSwitchPorts().size() == 2); // for two nodes. |
| 64 | assertTrue(tm.getSwitchPortLinks().size()==4); |
| 65 | assertTrue(tm.getPortBroadcastDomainLinks().size()==0); |
| 66 | assertTrue(tm.getTunnelPorts().size()==2); |
| 67 | |
| 68 | tm.removeLink((long)1, (short)1, (long)2, (short)1); |
| 69 | assertTrue(tm.getSwitchPorts().size() == 2); // for two nodes. |
| 70 | assertTrue(tm.getSwitchPorts().get((long)1).size()==1); |
| 71 | assertTrue(tm.getSwitchPorts().get((long)2).size()==1); |
| 72 | assertTrue(tm.getSwitchPortLinks().size()==2); |
| 73 | assertTrue(tm.getPortBroadcastDomainLinks().size()==0); |
| 74 | assertTrue(tm.getTunnelPorts().size()==2); |
| 75 | |
| 76 | tm.removeLink((long)1, (short)3, (long)2, (short)3); |
| 77 | assertTrue(tm.getSwitchPorts().size() == 0); |
| 78 | assertTrue(tm.getSwitchPortLinks().size()==0); |
| 79 | assertTrue(tm.getPortBroadcastDomainLinks().size()==0); |
| 80 | assertTrue(tm.getTunnelPorts().size()==0); |
| 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void testBasic2() throws Exception { |
| 85 | tm.addOrUpdateLink((long)1, (short)1, (long)2, (short)1, ILinkDiscovery.LinkType.DIRECT_LINK); |
| 86 | tm.addOrUpdateLink((long)2, (short)2, (long)3, (short)1, ILinkDiscovery.LinkType.MULTIHOP_LINK); |
| 87 | tm.addOrUpdateLink((long)3, (short)2, (long)1, (short)2, ILinkDiscovery.LinkType.TUNNEL); |
| 88 | assertTrue(tm.getSwitchPorts().size() == 3); // for two nodes. |
| 89 | assertTrue(tm.getSwitchPorts().get((long)1).size()==2); |
| 90 | assertTrue(tm.getSwitchPorts().get((long)2).size()==2); |
| 91 | assertTrue(tm.getSwitchPorts().get((long)3).size()==2); |
| 92 | assertTrue(tm.getSwitchPortLinks().size()==6); |
| 93 | assertTrue(tm.getPortBroadcastDomainLinks().size()==2); |
| 94 | assertTrue(tm.getTunnelPorts().size()==2); |
| 95 | |
| 96 | tm.removeLink((long)1, (short)1, (long)2, (short)1); |
| 97 | assertTrue(tm.getSwitchPorts().size() == 3); // for two nodes. |
| 98 | assertTrue(tm.getSwitchPorts().get((long)1).size()==1); |
| 99 | assertTrue(tm.getSwitchPorts().get((long)2).size()==1); |
| 100 | assertTrue(tm.getSwitchPorts().get((long)3).size()==2); |
| 101 | assertTrue(tm.getSwitchPortLinks().size()==4); |
| 102 | assertTrue(tm.getPortBroadcastDomainLinks().size()==2); |
| 103 | assertTrue(tm.getTunnelPorts().size()==2); |
| 104 | |
| 105 | // nonexistent link // no null pointer exceptions. |
| 106 | tm.removeLink((long)3, (short)1, (long)2, (short)2); |
| 107 | assertTrue(tm.getSwitchPorts().size() == 3); // for two nodes. |
| 108 | assertTrue(tm.getSwitchPorts().get((long)1).size()==1); |
| 109 | assertTrue(tm.getSwitchPorts().get((long)2).size()==1); |
| 110 | assertTrue(tm.getSwitchPorts().get((long)3).size()==2); |
| 111 | assertTrue(tm.getSwitchPortLinks().size()==4); |
| 112 | assertTrue(tm.getPortBroadcastDomainLinks().size()==2); |
| 113 | assertTrue(tm.getTunnelPorts().size()==2); |
| 114 | |
| 115 | tm.removeLink((long)3, (short)2, (long)1, (short)2); |
| 116 | assertTrue(tm.getSwitchPorts().size() == 2); // for two nodes. |
| 117 | assertTrue(tm.getSwitchPorts().get((long)1)==null); |
| 118 | assertTrue(tm.getSwitchPorts().get((long)2).size()==1); |
| 119 | assertTrue(tm.getSwitchPorts().get((long)3).size()==1); |
| 120 | assertTrue(tm.getSwitchPortLinks().size()==2); |
| 121 | assertTrue(tm.getPortBroadcastDomainLinks().size()==2); |
| 122 | assertTrue(tm.getTunnelPorts().size()==0); |
| 123 | |
| 124 | tm.removeLink((long)2, (short)2, (long)3, (short)1); |
| 125 | assertTrue(tm.getSwitchPorts().size() == 0); // for two nodes. |
| 126 | assertTrue(tm.getSwitchPortLinks().size()==0); |
| 127 | assertTrue(tm.getPortBroadcastDomainLinks().size()==0); |
| 128 | assertTrue(tm.getTunnelPorts().size()==0); |
| 129 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 130 | } |