Search in sources :

Example 21 with SpeakerSwitchView

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

the class NetworkSwitchServiceTest method portAddOnOnlineSwitch.

@Test
public void portAddOnOnlineSwitch() {
    NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
    // prepare
    SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder().ports(emptyList()).build();
    SwitchInfoData switchAddEvent = new SwitchInfoData(alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView);
    service.switchEvent(switchAddEvent);
    verifySwitchSync(service);
    // process
    Endpoint endpoint = Endpoint.of(alphaDatapath, 1);
    PortInfoData speakerPortEvent = new PortInfoData(endpoint.getDatapath(), endpoint.getPortNumber(), PortChangeType.ADD, true);
    service.switchPortEvent(speakerPortEvent);
    verify(carrier).sendSwitchStateChanged(alphaDatapath, SwitchStatus.ACTIVE);
    verify(carrier).setupPortHandler(endpoint, null);
    verify(carrier).setOnlineMode(endpoint, OnlineStatus.ONLINE);
    verify(carrier).setPortLinkMode(endpoint, LinkStatus.UP);
    verify(carrier).sendAffectedFlowRerouteRequest(alphaDatapath);
    verifyNoMoreInteractions(carrier);
}
Also used : Endpoint(org.openkilda.wfm.share.model.Endpoint) 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 22 with SpeakerSwitchView

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

the class NetworkSwitchServiceTest method portUpDownEventsOnOnlineSwitch.

@Test
public void portUpDownEventsOnOnlineSwitch() {
    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();
    // System.out.println(mockingDetails(carrier).printInvocations());
    service.switchPortEvent(new PortInfoData(alphaDatapath, 1, PortChangeType.UP));
    service.switchPortEvent(new PortInfoData(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET, PortChangeType.UP));
    List<SpeakerSwitchPortView> portsUp = ImmutableList.of(new SpeakerSwitchPortView(1, State.UP), new SpeakerSwitchPortView(1 + BFD_LOGICAL_PORT_OFFSET, State.UP));
    verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, portsUp.get(0).getNumber()), LinkStatus.of(portsUp.get(0).getState()));
    verify(carrier).sendBfdLinkStatusUpdate(Endpoint.of(alphaDatapath, portsUp.get(1).getNumber()), LinkStatus.of(portsUp.get(1).getState()));
    resetMocks();
    service.switchPortEvent(new PortInfoData(alphaDatapath, 1, PortChangeType.DOWN));
    service.switchPortEvent(new PortInfoData(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET, PortChangeType.DOWN));
    verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, portsDown.get(0).getNumber()), LinkStatus.of(portsDown.get(0).getState()));
    verify(carrier).sendBfdLinkStatusUpdate(Endpoint.of(alphaDatapath, portsDown.get(1).getNumber()), LinkStatus.of(portsDown.get(1).getState()));
// 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 23 with SpeakerSwitchView

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

the class NetworkSwitchServiceTest method switchMustStayOnlineIfItReceivePeriodicDumps.

@Test
public void switchMustStayOnlineIfItReceivePeriodicDumps() {
    NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
    SpeakerSwitchView dump = getSpeakerSwitchView();
    service.switchBecomeManaged(dump, "A-0");
    ArgumentCaptor<String> syncKeyCaptor = ArgumentCaptor.forClass(String.class);
    verify(carrier).sendSwitchSynchronizeRequest(syncKeyCaptor.capture(), eq(dump.getDatapath()));
    verifyNoMoreInteractions(carrier);
    String syncKey = syncKeyCaptor.getValue();
    SwitchSyncResponse response = makeSuccessSwitchSyncResponse(dump.getDatapath());
    service.switchManagerResponse(response, syncKey);
    verify(carrier).sendSwitchStateChanged(dump.getDatapath(), SwitchStatus.ACTIVE);
    verify(carrier).sendAffectedFlowRerouteRequest(dump.getDatapath());
    verifyNoMoreInteractions(carrier);
    // +10 to be sure to cover +-1 mismatches
    for (int i = 0; i < options.getSwitchOfflineGenerationLag() + 10; i++) {
        service.switchBecomeManaged(dump, String.format("dump#%d", i));
        verifyNoMoreInteractions(carrier);
    }
}
Also used : SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchSyncResponse(org.openkilda.messaging.info.switches.SwitchSyncResponse) Endpoint(org.openkilda.wfm.share.model.Endpoint) Test(org.junit.Test)

Example 24 with SpeakerSwitchView

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

the class NetworkSwitchServiceTest method newSwitchWithSynchronizationTimeout.

@Test
public void newSwitchWithSynchronizationTimeout() {
    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));
    service.switchManagerTimeout(alphaDatapath, captor.getValue());
    verify(carrier, times(SYNC_ATTEMPTS)).sendSwitchSynchronizeRequest(captor.capture(), eq(alphaDatapath));
    service.switchManagerTimeout(alphaDatapath, captor.getValue());
    verifyNewSwitchAfterSwitchSync(ports);
    verify(carrier).sendSwitchStateChanged(alphaDatapath, SwitchStatus.ACTIVE);
    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 25 with SpeakerSwitchView

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

the class NetworkSwitchServiceTest method newSwitchWithWrongSynchronizationResponse.

@Test
public void newSwitchWithWrongSynchronizationResponse() {
    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);
    RulesSyncEntry rulesSyncEntry = new RulesSyncEntry(singletonList(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue()), 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());
    // for a randomly generated key in SwitchFsm
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(carrier).sendSwitchSynchronizeRequest(captor.capture(), eq(alphaDatapath));
    service.switchManagerResponse(response, captor.getValue());
    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 : RulesSyncEntry(org.openkilda.messaging.info.switches.RulesSyncEntry) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) 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)

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