@Before public void SetUp() throws Exception { fmc = new FloodlightModuleContext(); linkDiscovery = EasyMock.createMock(ILinkDiscoveryService.class); mockFloodlightProvider = new MockFloodlightProvider(); fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider); fmc.addService(IOFSwitchService.class, new MockSwitchManager()); fmc.addService(ILinkDiscoveryService.class, linkDiscovery); fmc.addService(IDebugCounterService.class, new MockDebugCounterService()); fmc.addService(IDebugEventService.class, new MockDebugEventService()); MockThreadPoolService tp = new MockThreadPoolService(); topologyManager = new TopologyManager(); fmc.addService(IThreadPoolService.class, tp); topologyManager.init(fmc); tp.init(fmc); tp.startUp(fmc); }
@Before public void SetUp() throws Exception { fmc = new FloodlightModuleContext(); linkDiscovery = EasyMock.createMock(ILinkDiscoveryService.class); mockFloodlightProvider = new MockFloodlightProvider(); fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider); fmc.addService(ILinkDiscoveryService.class, linkDiscovery); fmc.addService(IDebugCounterService.class, new MockDebugCounterService()); fmc.addService(IDebugEventService.class, new MockDebugEventService()); MockThreadPoolService tp = new MockThreadPoolService(); topologyManager = new TopologyManager(); fmc.addService(IThreadPoolService.class, tp); topologyManager.init(fmc); tp.init(fmc); tp.startUp(fmc); }
@Test public void testFloodBufferId() throws Exception { MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider(); this.packetIn = this.packetIn.createBuilder() .setBufferId(OFBufferId.of(10)) .setXid(1) .build(); OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build(); List<OFAction> al = new ArrayList<OFAction>(); al.add(ao); // build our expected flooded packetOut OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut() .setActions(al) .setXid(1) .setBufferId(OFBufferId.of(10)) .setInPort(OFPort.of(1)) .build(); // Mock up our expected behavior IOFSwitch mockSwitch = createMock(IOFSwitch.class); EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes(); Capture<OFPacketOut> wc1 = new Capture<OFPacketOut>(CaptureType.ALL); expect(mockSwitch.write(capture(wc1))).andReturn(true).anyTimes(); // Start recording the replay on the mocks replay(mockSwitch); // Get the listener and trigger the packet in IOFMessageListener listener = mockFloodlightProvider.getListeners().get( OFType.PACKET_IN).get(0); listener.receive(mockSwitch, this.packetIn, parseAndAnnotate(this.packetIn)); // Verify the replay matched our expectations verify(mockSwitch); assertTrue(wc1.hasCaptured()); OFMessage m = wc1.getValue(); assertEquals(po, m); }
@Test public void testFloodBufferId() throws Exception { MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider(); this.packetIn = this.packetIn.createBuilder() .setBufferId(OFBufferId.of(10)) .setXid(1) .build(); OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build(); List<OFAction> al = new ArrayList<OFAction>(); al.add(ao); // build our expected flooded packetOut OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut() .setActions(al) .setXid(1) .setBufferId(OFBufferId.of(10)) .setInPort(OFPort.of(1)) .build(); // Mock up our expected behavior IOFSwitch mockSwitch = createMock(IOFSwitch.class); EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes(); Capture<OFPacketOut> wc1 = new Capture<OFPacketOut>(CaptureType.ALL); mockSwitch.write(capture(wc1)); // Start recording the replay on the mocks replay(mockSwitch); // Get the listener and trigger the packet in IOFMessageListener listener = mockFloodlightProvider.getListeners().get( OFType.PACKET_IN).get(0); listener.receive(mockSwitch, this.packetIn, parseAndAnnotate(this.packetIn)); // Verify the replay matched our expectations verify(mockSwitch); assertTrue(wc1.hasCaptured()); OFMessage m = wc1.getValue(); assertEquals(po, m); }
@Test public void testHARoleChanged() throws IOException { StaticFlowEntryPusher staticFlowEntryPusher = new StaticFlowEntryPusher(); IStorageSourceService storage = createStorageWithFlowEntries(); MockFloodlightProvider mfp = getMockFloodlightProvider(); staticFlowEntryPusher.setFloodlightProvider(mfp); staticFlowEntryPusher.setStorageSource(storage); RestApiServer restApi = new RestApiServer(); try { FloodlightModuleContext fmc = new FloodlightModuleContext(); restApi.init(fmc); } catch (FloodlightModuleException e) { e.printStackTrace(); } staticFlowEntryPusher.startUp(null); // again, to hack unittest // Send a notification that we've changed to slave // mfp.dispatchRoleChanged(null, Role.SLAVE); //#### mfp.dispatchMessage(Role.SLAVE, Role.MASTER); // Make sure we've removed all our entries // Send a notification that we've changed to master //##### mfp.dispatchRoleChanged(Role.SLAVE, Role.MASTER); // Make sure we've learned the entries }
@Test public void testFloodBufferId() throws Exception { MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider(); this.packetIn.setBufferId(10); // build our expected flooded packetOut OFPacketOut po = ((OFPacketOut) mockFloodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT)) .setActions(Arrays.asList(new OFAction[] {new OFActionOutput().setPort(OFPort.OFPP_FLOOD.getValue())})) .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH) .setBufferId(10) .setInPort((short) 1); po.setLengthU(OFPacketOut.MINIMUM_LENGTH + po.getActionsLengthU()); // Mock up our expected behavior IOFSwitch mockSwitch = createMock(IOFSwitch.class); Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL); Capture<FloodlightContext> bc1 = new Capture<FloodlightContext>(CaptureType.ALL); mockSwitch.write(capture(wc1), capture(bc1)); // Start recording the replay on the mocks replay(mockSwitch); // Get the listener and trigger the packet in IOFMessageListener listener = mockFloodlightProvider.getListeners().get( OFType.PACKET_IN).get(0); listener.receive(mockSwitch, this.packetIn, parseAndAnnotate(this.packetIn)); // Verify the replay matched our expectations verify(mockSwitch); assertTrue(wc1.hasCaptured()); OFMessage m = wc1.getValue(); assertEquals(po, m); }
@Override public void setUp() throws Exception { super.setUp(); staticFlowEntryPusher = new StaticFlowEntryPusher(); storage = createStorageWithFlowEntries(); dpid = HexString.toLong(TestSwitch1DPID); mockSwitch = createNiceMock(IOFSwitch.class); writeCapture = new Capture<OFMessage>(CaptureType.ALL); contextCapture = new Capture<FloodlightContext>(CaptureType.ALL); writeCaptureList = new Capture<List<OFMessage>>(CaptureType.ALL); //OFMessageSafeOutStream mockOutStream = createNiceMock(OFMessageSafeOutStream.class); mockSwitch.write(capture(writeCapture), capture(contextCapture)); expectLastCall().anyTimes(); mockSwitch.write(capture(writeCaptureList), capture(contextCapture)); expectLastCall().anyTimes(); mockSwitch.flush(); expectLastCall().anyTimes(); FloodlightModuleContext fmc = new FloodlightModuleContext(); fmc.addService(IStorageSourceService.class, storage); MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider(); Map<Long, IOFSwitch> switchMap = new HashMap<Long, IOFSwitch>(); switchMap.put(dpid, mockSwitch); // NO ! expect(mockFloodlightProvider.getSwitches()).andReturn(switchMap).anyTimes(); mockFloodlightProvider.setSwitches(switchMap); fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider); RestApiServer restApi = new RestApiServer(); fmc.addService(IRestApiService.class, restApi); restApi.init(fmc); staticFlowEntryPusher.init(fmc); staticFlowEntryPusher.startUp(fmc); // again, to hack unittest }
@Before public void SetUp() throws Exception { fmc = new FloodlightModuleContext(); linkDiscovery = EasyMock.createMock(ILinkDiscoveryService.class); mockFloodlightProvider = new MockFloodlightProvider(); fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider); fmc.addService(ILinkDiscoveryService.class, linkDiscovery); MockThreadPoolService tp = new MockThreadPoolService(); topologyManager = new TopologyManager(); fmc.addService(IThreadPoolService.class, tp); topologyManager.init(fmc); tp.init(fmc); tp.startUp(fmc); }
@Test public void testFloodBufferId() throws Exception { MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider(); this.packetIn.setBufferId(10); // build our expected flooded packetOut OFPacketOut po = ((OFPacketOut) mockFloodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT)) .setActions(Arrays.asList(new OFAction[] {new OFActionOutput().setPort(OFPort.OFPP_FLOOD.getValue())})) .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH) .setBufferId(10) .setInPort((short) 1); po.setLengthU(OFPacketOut.MINIMUM_LENGTH + po.getActionsLengthU()); // Mock up our expected behavior IOFSwitch mockSwitch = createMock(IOFSwitch.class); Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL); Capture<FloodlightContext> bc1 = new Capture<FloodlightContext>(CaptureType.ALL); mockSwitch.write(capture(wc1), capture(bc1)); // Start recording the replay on the mocks replay(mockSwitch); // Get the listener and trigger the packet in IOFMessageListener listener = mockFloodlightProvider.getListeners().get( OFType.PACKET_IN).get(0); listener.receive(mockSwitch, this.packetIn, parseAndAnnotate(this.packetIn)); // Verify the replay matched our expectations verify(mockSwitch); assertTrue(wc1.hasCaptured()); OFMessage m = wc1.getValue(); assert(m.equals(po)); }
@Test public void testHARoleChanged() throws IOException { StaticFlowEntryPusher staticFlowEntryPusher = new StaticFlowEntryPusher(); IStorageSourceService storage = createStorageWithFlowEntries(); MockFloodlightProvider mfp = getMockFloodlightProvider(); staticFlowEntryPusher.setFloodlightProvider(mfp); staticFlowEntryPusher.setStorageSource(storage); RestApiServer restApi = new RestApiServer(); try { FloodlightModuleContext fmc = new FloodlightModuleContext(); restApi.init(fmc); } catch (FloodlightModuleException e) { e.printStackTrace(); } staticFlowEntryPusher.restApi = restApi; staticFlowEntryPusher.startUp(null); // again, to hack unittest assert(staticFlowEntryPusher.entry2dpid.containsValue(TestSwitch1DPID)); assert(staticFlowEntryPusher.entriesFromStorage.containsValue(FlowMod1)); assert(staticFlowEntryPusher.entriesFromStorage.containsValue(FlowMod2)); assert(staticFlowEntryPusher.entriesFromStorage.containsValue(FlowMod3)); // Send a notification that we've changed to slave mfp.dispatchRoleChanged(null, Role.SLAVE); // Make sure we've removed all our entries assert(staticFlowEntryPusher.entry2dpid.isEmpty()); assert(staticFlowEntryPusher.entriesFromStorage.isEmpty()); // Send a notification that we've changed to master mfp.dispatchRoleChanged(Role.SLAVE, Role.MASTER); // Make sure we've learned the entries assert(staticFlowEntryPusher.entry2dpid.containsValue(TestSwitch1DPID)); assert(staticFlowEntryPusher.entriesFromStorage.containsValue(FlowMod1)); assert(staticFlowEntryPusher.entriesFromStorage.containsValue(FlowMod2)); assert(staticFlowEntryPusher.entriesFromStorage.containsValue(FlowMod3)); }
@Before public void SetUp() throws Exception { fmc = new FloodlightModuleContext(); mockFloodlightProvider = new MockFloodlightProvider(); fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider); MockThreadPoolService tp = new MockThreadPoolService(); topologyManager = new TopologyManager(); fmc.addService(IThreadPoolService.class, tp); topologyManager.init(fmc); tp.init(fmc); tp.startUp(fmc); }
@Before public void setUp() throws Exception { sw = new OFSwitchImpl(); Channel ch = createMock(Channel.class); SocketAddress sa = new InetSocketAddress(42); expect(ch.getRemoteAddress()).andReturn(sa).anyTimes(); sw.setChannel(ch); MockFloodlightProvider floodlightProvider = new MockFloodlightProvider(); sw.setFloodlightProvider(floodlightProvider); }
@Before public void before() { DTM.resetInstance(); dtm = DTM.getInstance(); dtm.setSwitch(null); dtm.setSwitch(sw); dtm.setFloodlightProvider(new MockFloodlightProvider()); dtm.setConfigData(TestSetUpHelper.CONFIG_DATA_2DC); }
@Before public void before() { DTM.resetInstance(); dtm = DTM.getInstance(); dtm.setSwitch(null); dtm.setSwitch(sw); dtm.setFloodlightProvider(new MockFloodlightProvider()); dtm.setConfigData(TestSetUpHelper.CONFIG_DATA_1DC); }
/** * Test the {@link DTM#setReferenceVector(eu.smartenit.sbox.db.dto.RVector)} * method. */ @Test public void testSetMultipleReferenceVectors() { dtm.setFloodlightProvider(new MockFloodlightProvider()); IOFSwitch switchMock = EasyMock.createNiceMock(IOFSwitch.class); expect(switchMock.getStringId()).andReturn("mock"); replay(switchMock); dtm.setSwitch(null); dtm.setSwitch(switchMock); dtm.setConfigData(TestSetUpHelper.CONFIG_DATA_2DC); RVector referenceVector1 = new RVector(); referenceVector1.setVectorValues(null); referenceVector1.addVectorValueForTunnelEndPrefix(new NetworkAddressIPv4(tunnelEndPrefix1, 24), 1); referenceVector1.addVectorValueForTunnelEndPrefix(new NetworkAddressIPv4(tunnelEndPrefix2, 24), 2); dtm.setReferenceVector(referenceVector1); RVector referenceVector2 = new RVector(); referenceVector2.setVectorValues(null); referenceVector2.addVectorValueForTunnelEndPrefix(new NetworkAddressIPv4(tunnelEndPrefix3, 24), 3); referenceVector2.addVectorValueForTunnelEndPrefix(new NetworkAddressIPv4(tunnelEndPrefix4, 24), 4); dtm.setReferenceVector(referenceVector2); RVector referenceVector3 = new RVector(); referenceVector3.setVectorValues(null); referenceVector3.addVectorValueForTunnelEndPrefix(new NetworkAddressIPv4(tunnelEndPrefix1, 24), 5); referenceVector3.addVectorValueForTunnelEndPrefix(new NetworkAddressIPv4(tunnelEndPrefix2, 24), 6); dtm.setReferenceVector(referenceVector3); assertEquals(4, dtm.rVectorMap.keySet().size()); assertEquals(4, dtm.daRouterRVectorMap.keySet().size()); assertEquals(5, (long) dtm.rVectorMap.get(new NetworkAddressIPv4(tunnelEndPrefix1, 24))); assertEquals(6, (long) dtm.daRouterRVectorMap.get((short) 2)); }