Search in sources :

Example 1 with HistoryFacts

use of org.openkilda.wfm.topology.network.model.facts.HistoryFacts in project open-kilda by telstra.

the class SwitchFsm method applyHistory.

// -- FSM actions --
public void applyHistory(SwitchFsmState from, SwitchFsmState to, SwitchFsmEvent event, SwitchFsmContext context) {
    HistoryFacts historyFacts = context.getHistory();
    for (Isl outgoingLink : historyFacts.getOutgoingLinks()) {
        PhysicalPort port = new PhysicalPort(Endpoint.of(switchId, outgoingLink.getSrcPort()));
        port.setHistory(outgoingLink);
        portAdd(port, context);
    }
    if (SwitchStatus.INACTIVE.equals(historyFacts.getLastRecordedStatus())) {
        fire(SwitchFsmEvent.OFFLINE, context);
    }
}
Also used : Isl(org.openkilda.model.Isl) HistoryFacts(org.openkilda.wfm.topology.network.model.facts.HistoryFacts)

Example 2 with HistoryFacts

use of org.openkilda.wfm.topology.network.model.facts.HistoryFacts in project open-kilda by telstra.

the class NetworkHistoryService method loadNetworkHistory.

// -- private --
private Collection<HistoryFacts> loadNetworkHistory() {
    RepositoryFactory repositoryFactory = persistenceManager.getRepositoryFactory();
    SwitchRepository switchRepository = repositoryFactory.createSwitchRepository();
    HashMap<SwitchId, HistoryFacts> switchById = new HashMap<>();
    for (Switch switchEntry : switchRepository.findAll()) {
        SwitchId switchId = switchEntry.getSwitchId();
        SwitchStatus switchStatus = switchEntry.getStatus();
        switchById.put(switchId, new HistoryFacts(switchId, switchStatus));
    }
    IslRepository islRepository = repositoryFactory.createIslRepository();
    for (Isl islEntry : islRepository.findAll()) {
        HistoryFacts history = switchById.get(islEntry.getSrcSwitchId());
        if (history == null) {
            log.error("Orphaned ISL relation - {}-{} (read race condition?)", islEntry.getSrcSwitchId(), islEntry.getSrcPort());
            continue;
        }
        islRepository.detach(islEntry);
        history.addLink(islEntry);
    }
    return switchById.values();
}
Also used : IslRepository(org.openkilda.persistence.repositories.IslRepository) Isl(org.openkilda.model.Isl) Switch(org.openkilda.model.Switch) HashMap(java.util.HashMap) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) SwitchId(org.openkilda.model.SwitchId) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) HistoryFacts(org.openkilda.wfm.topology.network.model.facts.HistoryFacts) SwitchStatus(org.openkilda.model.SwitchStatus)

Example 3 with HistoryFacts

use of org.openkilda.wfm.topology.network.model.facts.HistoryFacts in project open-kilda by telstra.

the class NetworkSwitchServiceTest method switchFromHistoryToOffline.

@Test
public void switchFromHistoryToOffline() {
    when(switchRepository.findById(alphaDatapath)).thenReturn(Optional.of(Switch.builder().switchId(alphaDatapath).build()));
    HistoryFacts history = new HistoryFacts(alphaDatapath, SwitchStatus.INACTIVE);
    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();
    history.addLink(islAtoB);
    history.addLink(islAtoB2);
    NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
    service.switchAddWithHistory(history);
    // System.out.println(mockingDetails(carrier).printInvocations());
    // System.out.println(mockingDetails(switchRepository).printInvocations());
    verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, 1), islAtoB);
    verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, 2), islAtoB2);
    verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, 1), OnlineStatus.OFFLINE);
    verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, 2), OnlineStatus.OFFLINE);
}
Also used : Isl(org.openkilda.model.Isl) Switch(org.openkilda.model.Switch) HistoryFacts(org.openkilda.wfm.topology.network.model.facts.HistoryFacts) Test(org.junit.Test)

Example 4 with HistoryFacts

use of org.openkilda.wfm.topology.network.model.facts.HistoryFacts 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 5 with HistoryFacts

use of org.openkilda.wfm.topology.network.model.facts.HistoryFacts in project open-kilda by telstra.

the class NetworkSwitchServiceTest method switchShouldBecomeOfflineEvenIfOfflineEventHaveBeenLost.

@Test
public void switchShouldBecomeOfflineEvenIfOfflineEventHaveBeenLost() {
    NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
    SpeakerSwitchView alpha = getSpeakerSwitchView();
    service.switchAddWithHistory(new HistoryFacts(betaDatapath, SwitchStatus.ACTIVE));
    verifyZeroInteractions(carrier);
    service.switchBecomeManaged(alpha, "A-0");
    verify(carrier).sendSwitchSynchronizeRequest(any(), eq(alpha.getDatapath()));
    verifyNoMoreInteractions(carrier);
    service.switchBecomeManaged(alpha, "A-1");
    verify(carrier).sendSwitchStateChanged(betaDatapath, SwitchStatus.INACTIVE);
    verifyNoMoreInteractions(carrier);
}
Also used : SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) HistoryFacts(org.openkilda.wfm.topology.network.model.facts.HistoryFacts) Test(org.junit.Test)

Aggregations

HistoryFacts (org.openkilda.wfm.topology.network.model.facts.HistoryFacts)5 Isl (org.openkilda.model.Isl)4 Test (org.junit.Test)3 Switch (org.openkilda.model.Switch)3 SpeakerSwitchView (org.openkilda.messaging.model.SpeakerSwitchView)2 HashMap (java.util.HashMap)1 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)1 SpeakerSwitchPortView (org.openkilda.messaging.model.SpeakerSwitchPortView)1 SwitchId (org.openkilda.model.SwitchId)1 SwitchStatus (org.openkilda.model.SwitchStatus)1 IslRepository (org.openkilda.persistence.repositories.IslRepository)1 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)1 SwitchRepository (org.openkilda.persistence.repositories.SwitchRepository)1