Search in sources :

Example 1 with NetworkDumpSwitchData

use of org.openkilda.messaging.info.discovery.NetworkDumpSwitchData in project open-kilda by telstra.

the class SpeakerToNetworkProxyBolt method proxyInfoMessage.

@Override
protected void proxyInfoMessage(String key, InfoMessage envelope) {
    emitAliveEvidence(envelope);
    InfoData payload = envelope.getData();
    if (payload instanceof AliveResponse) {
        emitRegionNotification(envelope.getRegion(), (AliveResponse) payload);
    } else if (payload instanceof SwitchInfoData) {
        emitNetworkNotification(envelope.getRegion(), (SwitchInfoData) payload);
    } else if (payload instanceof NetworkDumpSwitchData) {
        emitNetworkNotification(envelope.getRegion(), (NetworkDumpSwitchData) payload);
    } else if (payload instanceof PortInfoData) {
        emitNetworkNotification(envelope.getRegion(), (PortInfoData) payload);
    } else {
        super.proxyInfoMessage(key, envelope);
    }
}
Also used : AliveResponse(org.openkilda.messaging.AliveResponse) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) InfoData(org.openkilda.messaging.info.InfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData)

Example 2 with NetworkDumpSwitchData

use of org.openkilda.messaging.info.discovery.NetworkDumpSwitchData in project open-kilda by telstra.

the class SwitchMonitorServiceTest method testLoseActiveRegion.

@Test
public void testLoseActiveRegion() {
    SwitchMonitorService subject = makeSubject();
    Instant t0 = clock.instant();
    SwitchId targetSw = SWITCH_ALPHA;
    makeConnectInRegions(subject, targetSw, REGION_ALPHA, REGION_BETA);
    clock.adjust(Duration.ofSeconds(1));
    subject.handleRegionOfflineNotification(REGION_ALPHA);
    verify(carrier).regionUpdateNotification(eq(new RegionMappingSet(targetSw, REGION_BETA, true)));
    SpeakerSwitchView suggestedBetaSpeakerData = makeSwitchActivateNotification(targetSw, 2).getSwitchView();
    verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(targetSw), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_BETA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(suggestedBetaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedBetaSpeakerData.getSpeakerSocketAddress()).build()).build(), arg)));
    verifyNoMoreInteractions(carrier);
    reset(carrier);
    clock.adjust(Duration.ofSeconds(1));
    Instant t1 = clock.instant();
    SpeakerSwitchView suggestedAlphaSpeakerData = makeSwitchActivateNotification(targetSw, 1).getSwitchView();
    NetworkDumpSwitchData dumpBeta = new NetworkDumpSwitchData(suggestedAlphaSpeakerData, NETWORK_DUMP_CORRELATION_ID, true);
    subject.handleNetworkDumpResponse(dumpBeta, REGION_ALPHA);
    verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(targetSw), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_WRITE).master(false).connectedAt(t1).switchAddress(suggestedAlphaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedAlphaSpeakerData.getSpeakerSocketAddress()).build()).connection(SwitchAvailabilityEntry.builder().regionName(REGION_BETA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(suggestedBetaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedBetaSpeakerData.getSpeakerSocketAddress()).build()).build(), arg)));
    verifyNoMoreInteractions(carrier);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RegionMappingRemove(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove) SwitchAvailabilityData(org.openkilda.messaging.model.SwitchAvailabilityData) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) SwitchChangeType(org.openkilda.messaging.info.event.SwitchChangeType) SwitchConnectMode(org.openkilda.model.SwitchConnectMode) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) SpeakerSwitchDescription(org.openkilda.messaging.model.SpeakerSwitchDescription) Duration(java.time.Duration) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) RegionMappingSet(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet) SwitchMonitorCarrier(org.openkilda.wfm.topology.floodlightrouter.service.SwitchMonitorCarrier) State(org.openkilda.messaging.model.SpeakerSwitchPortView.State) SwitchAvailabilityEntry(org.openkilda.messaging.model.SwitchAvailabilityEntry) RegionMappingAdd(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingAdd) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData) IpSocketAddress(org.openkilda.model.IpSocketAddress) ManualClock(org.openkilda.stubs.ManualClock) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Objects(java.util.Objects) SwitchId(org.openkilda.model.SwitchId) Assert(org.junit.Assert) Comparator(java.util.Comparator) Mockito.reset(org.mockito.Mockito.reset) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) RegionMappingSet(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet) Instant(java.time.Instant) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchId(org.openkilda.model.SwitchId) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData) Test(org.junit.Test)

Example 3 with NetworkDumpSwitchData

use of org.openkilda.messaging.info.discovery.NetworkDumpSwitchData 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 4 with NetworkDumpSwitchData

use of org.openkilda.messaging.info.discovery.NetworkDumpSwitchData in project open-kilda by telstra.

the class SwitchMonitorBolt method handleNetworkUpdateNotification.

private void handleNetworkUpdateNotification(Tuple input) throws PipelineException {
    String region = pullRegion(input);
    InfoData payload = pullValue(input, SpeakerToNetworkProxyBolt.FIELD_ID_PAYLOAD, InfoData.class);
    if (payload instanceof SwitchInfoData) {
        service.handleStatusUpdateNotification((SwitchInfoData) payload, region);
    } else if (payload instanceof NetworkDumpSwitchData) {
        service.handleNetworkDumpResponse((NetworkDumpSwitchData) payload, region);
    } else if (payload instanceof PortInfoData) {
        service.handlePortStatusUpdateNotification((PortInfoData) payload, region);
    } else {
        unhandledInput(input);
    }
}
Also used : SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) InfoData(org.openkilda.messaging.info.InfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData)

Example 5 with NetworkDumpSwitchData

use of org.openkilda.messaging.info.discovery.NetworkDumpSwitchData in project open-kilda by telstra.

the class SwitchMonitorServiceTest method testLosePassiveRegion.

@Test
public void testLosePassiveRegion() {
    SwitchMonitorService subject = makeSubject();
    Instant t0 = clock.instant();
    SwitchId targetSw = SWITCH_ALPHA;
    makeConnectInRegions(subject, targetSw, REGION_ALPHA, REGION_BETA);
    clock.adjust(Duration.ofSeconds(1));
    subject.handleRegionOfflineNotification(REGION_BETA);
    SpeakerSwitchView suggestedAlphaSpeakerData = makeSwitchActivateNotification(targetSw, 1).getSwitchView();
    verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(targetSw), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(suggestedAlphaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedAlphaSpeakerData.getSpeakerSocketAddress()).build()).build(), arg)));
    verifyNoMoreInteractions(carrier);
    reset(carrier);
    clock.adjust(Duration.ofSeconds(1));
    Instant t1 = clock.instant();
    SpeakerSwitchView suggestedBetaSpeakerData = makeSwitchActivateNotification(targetSw, 2).getSwitchView();
    NetworkDumpSwitchData dumpBeta = new NetworkDumpSwitchData(suggestedBetaSpeakerData, NETWORK_DUMP_CORRELATION_ID, true);
    subject.handleNetworkDumpResponse(dumpBeta, REGION_BETA);
    verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(targetSw), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(suggestedAlphaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedAlphaSpeakerData.getSpeakerSocketAddress()).build()).connection(SwitchAvailabilityEntry.builder().regionName(REGION_BETA).connectMode(SwitchConnectMode.READ_WRITE).master(false).connectedAt(t1).switchAddress(suggestedBetaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedBetaSpeakerData.getSpeakerSocketAddress()).build()).build(), arg)));
    verifyNoMoreInteractions(carrier);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RegionMappingRemove(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove) SwitchAvailabilityData(org.openkilda.messaging.model.SwitchAvailabilityData) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) SwitchChangeType(org.openkilda.messaging.info.event.SwitchChangeType) SwitchConnectMode(org.openkilda.model.SwitchConnectMode) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) SpeakerSwitchDescription(org.openkilda.messaging.model.SpeakerSwitchDescription) Duration(java.time.Duration) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) RegionMappingSet(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet) SwitchMonitorCarrier(org.openkilda.wfm.topology.floodlightrouter.service.SwitchMonitorCarrier) State(org.openkilda.messaging.model.SpeakerSwitchPortView.State) SwitchAvailabilityEntry(org.openkilda.messaging.model.SwitchAvailabilityEntry) RegionMappingAdd(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingAdd) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData) IpSocketAddress(org.openkilda.model.IpSocketAddress) ManualClock(org.openkilda.stubs.ManualClock) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Objects(java.util.Objects) SwitchId(org.openkilda.model.SwitchId) Assert(org.junit.Assert) Comparator(java.util.Comparator) Mockito.reset(org.mockito.Mockito.reset) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) Instant(java.time.Instant) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchId(org.openkilda.model.SwitchId) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData) Test(org.junit.Test)

Aggregations

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