Search in sources :

Example 16 with SpeakerSwitchPortView

use of org.openkilda.messaging.model.SpeakerSwitchPortView 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 17 with SpeakerSwitchPortView

use of org.openkilda.messaging.model.SpeakerSwitchPortView 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 18 with SpeakerSwitchPortView

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

Example 19 with SpeakerSwitchPortView

use of org.openkilda.messaging.model.SpeakerSwitchPortView 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 20 with SpeakerSwitchPortView

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

Aggregations

SpeakerSwitchPortView (org.openkilda.messaging.model.SpeakerSwitchPortView)20 SpeakerSwitchView (org.openkilda.messaging.model.SpeakerSwitchView)17 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)16 Test (org.junit.Test)15 InetSocketAddress (java.net.InetSocketAddress)3 ArrayList (java.util.ArrayList)3 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)3 SwitchDescription (net.floodlightcontroller.core.SwitchDescription)3 GroupSyncEntry (org.openkilda.messaging.info.switches.GroupSyncEntry)3 RulesSyncEntry (org.openkilda.messaging.info.switches.RulesSyncEntry)3 SwitchSyncResponse (org.openkilda.messaging.info.switches.SwitchSyncResponse)3 SpeakerSwitchDescription (org.openkilda.messaging.model.SpeakerSwitchDescription)3 IpSocketAddress (org.openkilda.model.IpSocketAddress)3 HashSet (java.util.HashSet)2 OFConnection (net.floodlightcontroller.core.internal.OFConnection)2 Message (org.openkilda.messaging.Message)2 SwitchSyncErrorData (org.openkilda.messaging.error.rule.SwitchSyncErrorData)2 InfoMessage (org.openkilda.messaging.info.InfoMessage)2 NetworkDumpSwitchData (org.openkilda.messaging.info.discovery.NetworkDumpSwitchData)2 PortInfoData (org.openkilda.messaging.info.event.PortInfoData)2