Search in sources :

Example 16 with SpeakerSwitchView

use of org.openkilda.messaging.model.SpeakerSwitchView in project open-kilda by telstra.

the class SwitchTrackingServiceTest method networkDumpTest.

@Test
public void networkDumpTest() throws Exception {
    // Cook mock data for ISwitchManager::getAllSwitchMap
    // Two switches with two ports on each
    // switches for ISwitchManager::getAllSwitchMap
    OFSwitch iofSwitch1 = mock(OFSwitch.class);
    OFSwitch iofSwitch2 = mock(OFSwitch.class);
    final DatapathId swAid = DatapathId.of(1);
    final DatapathId swBid = DatapathId.of(2);
    Map<DatapathId, IOFSwitch> switches = ImmutableMap.of(swAid, iofSwitch1, swBid, iofSwitch2);
    Map<DatapathId, InetSocketAddress> switchAddresses = ImmutableMap.of(swAid, new InetSocketAddress(Inet4Address.getByName("127.0.1.1"), 32768), swBid, new InetSocketAddress(Inet4Address.getByName("127.0.1.2"), 32768));
    SwitchDescription ofSwitchDescription = new SwitchDescription(switchDescription.getManufacturer(), switchDescription.getHardware(), switchDescription.getSoftware(), switchDescription.getSerialNumber(), switchDescription.getDatapath());
    OFFactoryVer13 ofFactory = new OFFactoryVer13();
    InetSocketAddress switchSocketAddress = new InetSocketAddress(Inet4Address.getByName("127.0.1.1"), 32768);
    for (DatapathId swId : switches.keySet()) {
        IOFSwitch sw = switches.get(swId);
        expect(sw.getOFFactory()).andStubReturn(ofFactory);
        expect(sw.isActive()).andReturn(true).anyTimes();
        expect(sw.getId()).andReturn(swId).anyTimes();
        expect(sw.getSwitchDescription()).andReturn(ofSwitchDescription);
        expect(sw.getInetAddress()).andReturn(switchAddresses.get(swId));
        expect(sw.getControllerRole()).andStubReturn(OFControllerRole.ROLE_EQUAL);
        OFConnection connect = createMock(OFConnection.class);
        expect(connect.getRemoteInetAddress()).andReturn(switchSocketAddress);
        expect(sw.getConnectionByCategory(eq(LogicalOFMessageCategory.MAIN))).andReturn(connect);
    }
    expect(switchManager.getAllSwitchMap(true)).andReturn(switches);
    expect(switchManager.getPhysicalPorts(eq(iofSwitch1))).andReturn(ImmutableList.of(makePhysicalPortMock(1, true), makePhysicalPortMock(2, true)));
    expect(switchManager.getPhysicalPorts(eq(iofSwitch2))).andReturn(ImmutableList.of(makePhysicalPortMock(3, true), makePhysicalPortMock(4, true), makePhysicalPortMock(5, false)));
    expect(featureDetector.detectSwitch(iofSwitch1)).andReturn(ImmutableSet.of(SwitchFeature.METERS));
    expect(featureDetector.detectSwitch(iofSwitch2)).andReturn(ImmutableSet.of(SwitchFeature.METERS, SwitchFeature.BFD));
    ArrayList<Message> producedMessages = new ArrayList<>();
    // setup hook for verify that we create new message for producer
    producerService.sendMessageAndTrack(eq(KAFKA_ISL_DISCOVERY_TOPIC), anyObject(), anyObject(InfoMessage.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() {
            Message sentMessage = (Message) getCurrentArguments()[2];
            sentMessage.setTimestamp(0);
            producedMessages.add(sentMessage);
            return null;
        }
    }).anyTimes();
    replayAll();
    String correlationId = "unit-test-correlation-id";
    String dumpId = "dummy-dump-id";
    try (CorrelationContextClosable dummy = CorrelationContext.create(correlationId)) {
        service.dumpAllSwitches(dumpId);
    }
    verify(producerService);
    ArrayList<Message> expectedMessages = new ArrayList<>();
    expectedMessages.add(new InfoMessage(new NetworkDumpSwitchData(new SpeakerSwitchView(new SwitchId(swAid.getLong()), new IpSocketAddress("127.0.1.1", 32768), new IpSocketAddress("127.0.1.254", 6653), "127.0.1.1", "OF_13", switchDescription, ImmutableSet.of(SwitchFeature.METERS), ImmutableList.of(new SpeakerSwitchPortView(1, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(2, SpeakerSwitchPortView.State.UP))), dumpId, true), 0, correlationId));
    expectedMessages.add(new InfoMessage(new NetworkDumpSwitchData(new SpeakerSwitchView(new SwitchId(swBid.getLong()), new IpSocketAddress("127.0.1.2", 32768), new IpSocketAddress("127.0.1.254", 6653), "127.0.1.2", "OF_13", switchDescription, ImmutableSet.of(SwitchFeature.METERS, SwitchFeature.BFD), ImmutableList.of(new SpeakerSwitchPortView(3, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(4, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(5, SpeakerSwitchPortView.State.DOWN))), dumpId, true), 0, correlationId));
    assertEquals(expectedMessages, producedMessages);
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFConnection(net.floodlightcontroller.core.internal.OFConnection) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) CorrelationContextClosable(org.openkilda.floodlight.utils.CorrelationContext.CorrelationContextClosable) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchId(org.openkilda.model.SwitchId) IpSocketAddress(org.openkilda.model.IpSocketAddress) IAnswer(org.easymock.IAnswer) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) InfoMessage(org.openkilda.messaging.info.InfoMessage) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFSwitch(net.floodlightcontroller.core.internal.OFSwitch) SpeakerSwitchDescription(org.openkilda.messaging.model.SpeakerSwitchDescription) SwitchDescription(net.floodlightcontroller.core.SwitchDescription) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData) Test(org.junit.Test)

Example 17 with SpeakerSwitchView

use of org.openkilda.messaging.model.SpeakerSwitchView in project open-kilda by telstra.

the class SwitchTrackingServiceTest method switchActivate.

@Test
public void switchActivate() throws Exception {
    SpeakerSwitchView expectedSwitchView = makeSwitchRecord(dpId, switchFeatures, true, true);
    switchActivateTest(prepareAliveSwitchEvent(expectedSwitchView), expectedSwitchView);
}
Also used : SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) Test(org.junit.Test)

Example 18 with SpeakerSwitchView

use of org.openkilda.messaging.model.SpeakerSwitchView in project open-kilda by telstra.

the class NetworkIntegrationTest method switchAdd.

@Test
@Ignore
public void switchAdd() {
    Set<SwitchFeature> features = new HashSet<>();
    features.add(SwitchFeature.BFD);
    Integer bfdLocalPortOffset = options.getBfdLogicalPortOffset();
    List<SpeakerSwitchPortView> ports = ImmutableList.of(new SpeakerSwitchPortView(1, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(1 + bfdLocalPortOffset, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(2, SpeakerSwitchPortView.State.DOWN), new SpeakerSwitchPortView(2 + bfdLocalPortOffset, SpeakerSwitchPortView.State.DOWN));
    SpeakerSwitchView speakerSwitchView = new SpeakerSwitchView(alphaDatapath, new IpSocketAddress(alphaInetAddress.getHostString(), alphaInetAddress.getPort()), new IpSocketAddress(speakerInetAddress.getHostString(), speakerInetAddress.getPort()), alphaInetAddress.getHostString(), "OF_13", switchDescription, features, ports);
    NetworkSwitchService switchService = integrationCarrier.getSwitchService();
    SwitchInfoData switchAddEvent = new SwitchInfoData(alphaDatapath, SwitchChangeType.ADDED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView);
    switchService.switchEvent(switchAddEvent);
    SwitchInfoData switchActivateEvent = new SwitchInfoData(alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView);
    switchService.switchEvent(switchActivateEvent);
}
Also used : SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) SwitchFeature(org.openkilda.model.SwitchFeature) IpSocketAddress(org.openkilda.model.IpSocketAddress) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with SpeakerSwitchView

use of org.openkilda.messaging.model.SpeakerSwitchView in project open-kilda by telstra.

the class NetworkSwitchServiceTest method switchWithNoBfdSupport.

@Test
public void switchWithNoBfdSupport() {
    List<SpeakerSwitchPortView> ports = getSpeakerSwitchPortViews();
    SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder().ports(ports).features(Collections.emptySet()).build();
    SwitchInfoData switchAddEvent = new SwitchInfoData(alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView);
    NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
    service.switchEvent(switchAddEvent);
    verifySwitchSync(service);
    // System.out.println(mockingDetails(carrier).printInvocations());
    // System.out.println(mockingDetails(switchRepository).printInvocations());
    verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, ports.get(0).getNumber()), null);
    verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, ports.get(1).getNumber()), null);
    verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, ports.get(2).getNumber()), null);
    verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, ports.get(3).getNumber()), null);
    verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(0).getNumber()), OnlineStatus.ONLINE);
    verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(1).getNumber()), OnlineStatus.ONLINE);
    verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(2).getNumber()), OnlineStatus.ONLINE);
    verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(3).getNumber()), OnlineStatus.ONLINE);
    verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, ports.get(2).getNumber()), LinkStatus.of(ports.get(2).getState()));
    verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, ports.get(3).getNumber()), LinkStatus.of(ports.get(3).getState()));
    verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, ports.get(0).getNumber()), LinkStatus.of(ports.get(0).getState()));
    verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, ports.get(1).getNumber()), LinkStatus.of(ports.get(0).getState()));
}
Also used : SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test)

Example 20 with SpeakerSwitchView

use of org.openkilda.messaging.model.SpeakerSwitchView in project open-kilda by telstra.

the class NetworkSwitchServiceTest method newSwitchWithNullMetersInSynchronizationResponse.

@Test
public void newSwitchWithNullMetersInSynchronizationResponse() {
    List<SpeakerSwitchPortView> ports = getSpeakerSwitchPortViews();
    SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder().ports(ports).build();
    SwitchInfoData switchAddEvent = new SwitchInfoData(alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView);
    NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
    service.switchEvent(switchAddEvent);
    // for a randomly generated key in SwitchFsm
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(carrier).sendSwitchSynchronizeRequest(captor.capture(), eq(alphaDatapath));
    RulesSyncEntry rulesSyncEntry = new RulesSyncEntry(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
    GroupSyncEntry groupSyncEntry = new GroupSyncEntry(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
    SwitchSyncResponse response = new SwitchSyncResponse(alphaDatapath, rulesSyncEntry, null, groupSyncEntry, LogicalPortsSyncEntry.builder().build());
    service.switchManagerResponse(response, captor.getValue());
    verifyNewSwitchAfterSwitchSync(ports);
    verify(carrier).sendSwitchStateChanged(alphaDatapath, SwitchStatus.ACTIVE);
    verifyNoMoreInteractions(carrier);
}
Also used : RulesSyncEntry(org.openkilda.messaging.info.switches.RulesSyncEntry) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchSyncResponse(org.openkilda.messaging.info.switches.SwitchSyncResponse) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) GroupSyncEntry(org.openkilda.messaging.info.switches.GroupSyncEntry) Test(org.junit.Test)

Aggregations

SpeakerSwitchView (org.openkilda.messaging.model.SpeakerSwitchView)29 Test (org.junit.Test)25 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)23 SpeakerSwitchPortView (org.openkilda.messaging.model.SpeakerSwitchPortView)21 IpSocketAddress (org.openkilda.model.IpSocketAddress)8 NetworkDumpSwitchData (org.openkilda.messaging.info.discovery.NetworkDumpSwitchData)6 SpeakerSwitchDescription (org.openkilda.messaging.model.SpeakerSwitchDescription)6 SwitchId (org.openkilda.model.SwitchId)6 Duration (java.time.Duration)4 Instant (java.time.Instant)4 Collections (java.util.Collections)4 Comparator (java.util.Comparator)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 Assert (org.junit.Assert)4 RunWith (org.junit.runner.RunWith)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)4 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)4 Mock (org.mockito.Mock)4