Search in sources :

Example 1 with SpeakerSwitchPortView

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

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

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

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

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

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