Search in sources :

Example 6 with SpeakerSwitchView

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

the class NetworkSwitchServiceTest method switchFromOnlineToOfflineToOnline.

@Test
public void switchFromOnlineToOfflineToOnline() {
    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);
    SwitchInfoData deactivatedSwitch = switchAddEvent.toBuilder().state(SwitchChangeType.DEACTIVATED).build();
    service.switchEvent(deactivatedSwitch);
    List<SpeakerSwitchPortView> ports2 = getSpeakerSwitchPortViewsRevert();
    SpeakerSwitchView speakerSwitchView2 = getSpeakerSwitchView().toBuilder().ports(ports2).build();
    SwitchInfoData switchAddEvent2 = new SwitchInfoData(alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView2);
    resetMocks();
    service.switchEvent(switchAddEvent2);
    verifySwitchSync(service);
    // System.out.println(mockingDetails(carrier).printInvocations());
    // System.out.println(mockingDetails(switchRepository).printInvocations());
    verify(carrier).sendSwitchStateChanged(eq(alphaDatapath), eq(SwitchStatus.ACTIVE));
    verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(0).getNumber()), OnlineStatus.ONLINE);
    verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(2).getNumber()), OnlineStatus.ONLINE);
    verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, ports2.get(2).getNumber()), LinkStatus.of(ports2.get(2).getState()));
    verify(carrier).sendBfdLinkStatusUpdate(Endpoint.of(alphaDatapath, ports2.get(3).getNumber()), LinkStatus.of(ports2.get(3).getState()));
    verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, ports2.get(0).getNumber()), LinkStatus.of(ports2.get(0).getState()));
    verify(carrier).sendBfdLinkStatusUpdate(Endpoint.of(alphaDatapath, ports2.get(1).getNumber()), LinkStatus.of(ports2.get(0).getState()));
    verify(carrier).sendAffectedFlowRerouteRequest(alphaDatapath);
}
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 7 with SpeakerSwitchView

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

the class NetworkSwitchServiceTest method portDelEventOnOnlineSwitch.

@Test
public void portDelEventOnOnlineSwitch() {
    List<SpeakerSwitchPortView> portsDown = ImmutableList.of(new SpeakerSwitchPortView(1, State.DOWN), new SpeakerSwitchPortView(1 + BFD_LOGICAL_PORT_OFFSET, State.DOWN));
    SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder().ports(portsDown).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();
    service.switchPortEvent(new PortInfoData(alphaDatapath, 1, PortChangeType.DELETE));
    service.switchPortEvent(new PortInfoData(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET, PortChangeType.DELETE));
    verify(carrier).removePortHandler(Endpoint.of(alphaDatapath, 1));
    verify(carrier).sendBfdPortDelete(Endpoint.of(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET));
// System.out.println(mockingDetails(carrier).printInvocations());
}
Also used : SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test)

Example 8 with SpeakerSwitchView

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

the class NetworkSwitchServiceTest method switchFromHistoryToOfflineToOnlineRemovedPort.

@Test
public void switchFromHistoryToOfflineToOnlineRemovedPort() {
    // History
    HistoryFacts history = new HistoryFacts(alphaDatapath, SwitchStatus.ACTIVE);
    Switch alphaSwitch = Switch.builder().switchId(alphaDatapath).build();
    Switch betaSwitch = Switch.builder().switchId(betaDatapath).build();
    Isl islAtoB = Isl.builder().srcSwitch(alphaSwitch).srcPort(1).destSwitch(betaSwitch).destPort(1).build();
    Isl islAtoB2 = Isl.builder().srcSwitch(alphaSwitch).srcPort(2).destSwitch(betaSwitch).destPort(2).build();
    Isl islAtoB3 = Isl.builder().srcSwitch(alphaSwitch).srcPort(3).destSwitch(betaSwitch).destPort(3).build();
    history.addLink(islAtoB);
    history.addLink(islAtoB2);
    history.addLink(islAtoB3);
    NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
    service.switchAddWithHistory(history);
    // Online
    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);
    resetMocks();
    service.switchEvent(switchAddEvent);
    verifySwitchSync(service);
    verify(carrier).removePortHandler(Endpoint.of(alphaDatapath, 3));
// System.out.println(mockingDetails(carrier).printInvocations());
// System.out.println(mockingDetails(switchRepository).printInvocations());
}
Also used : Isl(org.openkilda.model.Isl) Switch(org.openkilda.model.Switch) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) HistoryFacts(org.openkilda.wfm.topology.network.model.facts.HistoryFacts) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test)

Example 9 with SpeakerSwitchView

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

the class NetworkSwitchServiceTest method switchFromOnlineToOnline.

@Test
public void switchFromOnlineToOnline() {
    List<SpeakerSwitchPortView> ports = Lists.newArrayList(new SpeakerSwitchPortView(1, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(1 + BFD_LOGICAL_PORT_OFFSET, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(2, SpeakerSwitchPortView.State.DOWN), new SpeakerSwitchPortView(2 + BFD_LOGICAL_PORT_OFFSET, SpeakerSwitchPortView.State.DOWN), new SpeakerSwitchPortView(3, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(3 + BFD_LOGICAL_PORT_OFFSET, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(4, SpeakerSwitchPortView.State.DOWN), new SpeakerSwitchPortView(4 + BFD_LOGICAL_PORT_OFFSET, SpeakerSwitchPortView.State.DOWN));
    SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder().ports(ImmutableList.copyOf(ports)).build();
    SwitchInfoData switchAddEvent = new SwitchInfoData(alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView);
    NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
    // initial switch ADD
    service.switchEvent(switchAddEvent);
    verifySwitchSync(service);
    resetMocks();
    // periodic network sync (swap UP/DOWN state for half of the ports)
    for (int idx = 0; idx < 4 && idx < ports.size(); idx++) {
        ports.set(idx, makePortEntryWithOppositeState(ports.get(idx)));
    }
    SpeakerSwitchView periodicSyncEvent = speakerSwitchView.toBuilder().ports(ImmutableList.copyOf(ports)).build();
    service.switchBecomeManaged(periodicSyncEvent, DUMMY_CORRELATION_ID);
    // only changed ports
    verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, 1), LinkStatus.DOWN);
    verify(carrier).sendBfdLinkStatusUpdate(Endpoint.of(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET), LinkStatus.DOWN);
    verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, 2), LinkStatus.UP);
    verify(carrier).sendBfdLinkStatusUpdate(Endpoint.of(alphaDatapath, 2 + BFD_LOGICAL_PORT_OFFSET), LinkStatus.UP);
    verifyNoMoreInteractions(carrier);
}
Also used : SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Endpoint(org.openkilda.wfm.share.model.Endpoint) Test(org.junit.Test)

Example 10 with SpeakerSwitchView

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

the class NetworkSwitchServiceTest method newSwitchWithSynchronizationErrorResponse.

@Test
public void newSwitchWithSynchronizationErrorResponse() {
    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());
    verify(carrier, times(SYNC_ATTEMPTS)).sendSwitchSynchronizeRequest(captor.capture(), eq(alphaDatapath));
    service.switchManagerErrorResponse(errorData, captor.getValue());
    verifyNewSwitchAfterSwitchSync(ports);
    verify(carrier).sendSwitchStateChanged(alphaDatapath, SwitchStatus.ACTIVE);
    verifyNoMoreInteractions(carrier);
}
Also used : SwitchSyncErrorData(org.openkilda.messaging.error.rule.SwitchSyncErrorData) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) 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