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);
}
}
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();
}
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);
}
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());
}
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);
}
Aggregations