@Test public void switchFromOnlineToOffline() { List<SpeakerSwitchPortView> ports = getSpeakerSwitchPortViews(); SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder() .ports(ports) .build(); SwitchInfoData switchAddEvent = new SwitchInfoData( alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), 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); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(0).getNumber()), OnlineStatus.OFFLINE); verify(carrier).setBfdPortOnlineMode(Endpoint.of(alphaDatapath, ports.get(1).getNumber()), false); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(2).getNumber()), OnlineStatus.OFFLINE); verify(carrier).setBfdPortOnlineMode(Endpoint.of(alphaDatapath, ports.get(3).getNumber()), false); }
public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager,
                                NetworkOptions options); }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager,
                                NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager,
                                NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath);  }