Search in sources :

Example 26 with SpeakerSwitchView

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

the class NetworkSwitchServiceTest method switchFromOnlineToOffline.

@Test
public void switchFromOnlineToOffline() {
    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);
    verifySwitchSync(service);
    resetMocks();
    when(switchRepository.findById(alphaDatapath)).thenReturn(Optional.of(Switch.builder().switchId(alphaDatapath).build()));
    SwitchInfoData deactivatedSwitch = switchAddEvent.toBuilder().state(SwitchChangeType.DEACTIVATED).build();
    service.switchEvent(deactivatedSwitch);
    // System.out.println(mockingDetails(carrier).printInvocations());
    // System.out.println(mockingDetails(switchRepository).printInvocations());
    verify(carrier).sendSwitchStateChanged(eq(alphaDatapath), eq(SwitchStatus.INACTIVE));
    verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(0).getNumber()), OnlineStatus.OFFLINE);
    verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(2).getNumber()), OnlineStatus.OFFLINE);
    verifyNoMoreInteractions(carrier);
}
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 27 with SpeakerSwitchView

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

the class NetworkSwitchServiceTest method newSwitchWithSynchronizationSuccessAfterError.

@Test
public void newSwitchWithSynchronizationSuccessAfterError() {
    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));
    SwitchSyncErrorData errorData = new SwitchSyncErrorData(alphaDatapath, null, null, null);
    service.switchManagerErrorResponse(errorData, captor.getValue());
    RulesSyncEntry rulesSyncEntry = new RulesSyncEntry(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
    MetersSyncEntry metersSyncEntry = new MetersSyncEntry(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
    GroupSyncEntry groupSyncEntry = new GroupSyncEntry(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
    SwitchSyncResponse response = new SwitchSyncResponse(alphaDatapath, rulesSyncEntry, metersSyncEntry, groupSyncEntry, LogicalPortsSyncEntry.builder().build());
    verify(carrier, times(SYNC_ATTEMPTS)).sendSwitchSynchronizeRequest(captor.capture(), eq(alphaDatapath));
    service.switchManagerResponse(response, captor.getValue());
    verifyNewSwitchAfterSwitchSync(ports);
    verify(carrier).sendSwitchStateChanged(alphaDatapath, SwitchStatus.ACTIVE);
    verifyNoMoreInteractions(carrier);
}
Also used : SwitchSyncErrorData(org.openkilda.messaging.error.rule.SwitchSyncErrorData) RulesSyncEntry(org.openkilda.messaging.info.switches.RulesSyncEntry) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) MetersSyncEntry(org.openkilda.messaging.info.switches.MetersSyncEntry) 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)

Example 28 with SpeakerSwitchView

use of org.openkilda.messaging.model.SpeakerSwitchView 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)

Example 29 with SpeakerSwitchView

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

the class SwitchMonitorServiceTest method makeSwitchActivateNotification.

private SwitchInfoData makeSwitchActivateNotification(SwitchId switchId, int network) {
    String swAddress = String.format("127.0.%d.2", network);
    SpeakerSwitchView speakerView = SpeakerSwitchView.builder().datapath(switchId).switchSocketAddress(new IpSocketAddress(swAddress, 32769)).speakerSocketAddress(new IpSocketAddress(String.format("127.0.%d.1", network), 6653)).ofVersion("OF_13").description(SpeakerSwitchDescription.builder().manufacturer("manufacturer").hardware("hardware").software("software").serialNumber("1").datapath(switchId.toString()).build()).features(Collections.emptySet()).port(SpeakerSwitchPortView.builder().number(1).state(State.UP).build()).port(SpeakerSwitchPortView.builder().number(2).state(State.DOWN).build()).build();
    return new SwitchInfoData(SWITCH_ALPHA, SwitchChangeType.ACTIVATED, swAddress, String.format("%s %s %s", speakerView.getDescription().getManufacturer(), speakerView.getOfVersion(), speakerView.getDescription().getSoftware()), "controller", false, speakerView);
}
Also used : SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) IpSocketAddress(org.openkilda.model.IpSocketAddress)

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