use of org.openkilda.messaging.info.discovery.NetworkDumpSwitchData in project open-kilda by telstra.
the class SpeakerToNetworkProxyBolt method proxyInfoMessage.
@Override
protected void proxyInfoMessage(String key, InfoMessage envelope) {
emitAliveEvidence(envelope);
InfoData payload = envelope.getData();
if (payload instanceof AliveResponse) {
emitRegionNotification(envelope.getRegion(), (AliveResponse) payload);
} else if (payload instanceof SwitchInfoData) {
emitNetworkNotification(envelope.getRegion(), (SwitchInfoData) payload);
} else if (payload instanceof NetworkDumpSwitchData) {
emitNetworkNotification(envelope.getRegion(), (NetworkDumpSwitchData) payload);
} else if (payload instanceof PortInfoData) {
emitNetworkNotification(envelope.getRegion(), (PortInfoData) payload);
} else {
super.proxyInfoMessage(key, envelope);
}
}
use of org.openkilda.messaging.info.discovery.NetworkDumpSwitchData in project open-kilda by telstra.
the class SwitchMonitorServiceTest method testLoseActiveRegion.
@Test
public void testLoseActiveRegion() {
SwitchMonitorService subject = makeSubject();
Instant t0 = clock.instant();
SwitchId targetSw = SWITCH_ALPHA;
makeConnectInRegions(subject, targetSw, REGION_ALPHA, REGION_BETA);
clock.adjust(Duration.ofSeconds(1));
subject.handleRegionOfflineNotification(REGION_ALPHA);
verify(carrier).regionUpdateNotification(eq(new RegionMappingSet(targetSw, REGION_BETA, true)));
SpeakerSwitchView suggestedBetaSpeakerData = makeSwitchActivateNotification(targetSw, 2).getSwitchView();
verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(targetSw), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_BETA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(suggestedBetaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedBetaSpeakerData.getSpeakerSocketAddress()).build()).build(), arg)));
verifyNoMoreInteractions(carrier);
reset(carrier);
clock.adjust(Duration.ofSeconds(1));
Instant t1 = clock.instant();
SpeakerSwitchView suggestedAlphaSpeakerData = makeSwitchActivateNotification(targetSw, 1).getSwitchView();
NetworkDumpSwitchData dumpBeta = new NetworkDumpSwitchData(suggestedAlphaSpeakerData, NETWORK_DUMP_CORRELATION_ID, true);
subject.handleNetworkDumpResponse(dumpBeta, REGION_ALPHA);
verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(targetSw), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_WRITE).master(false).connectedAt(t1).switchAddress(suggestedAlphaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedAlphaSpeakerData.getSpeakerSocketAddress()).build()).connection(SwitchAvailabilityEntry.builder().regionName(REGION_BETA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(suggestedBetaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedBetaSpeakerData.getSpeakerSocketAddress()).build()).build(), arg)));
verifyNoMoreInteractions(carrier);
}
use of org.openkilda.messaging.info.discovery.NetworkDumpSwitchData in project open-kilda by telstra.
the class SwitchTrackingServiceTest method networkDumpTest.
@Test
public void networkDumpTest() throws Exception {
// Cook mock data for ISwitchManager::getAllSwitchMap
// Two switches with two ports on each
// switches for ISwitchManager::getAllSwitchMap
OFSwitch iofSwitch1 = mock(OFSwitch.class);
OFSwitch iofSwitch2 = mock(OFSwitch.class);
final DatapathId swAid = DatapathId.of(1);
final DatapathId swBid = DatapathId.of(2);
Map<DatapathId, IOFSwitch> switches = ImmutableMap.of(swAid, iofSwitch1, swBid, iofSwitch2);
Map<DatapathId, InetSocketAddress> switchAddresses = ImmutableMap.of(swAid, new InetSocketAddress(Inet4Address.getByName("127.0.1.1"), 32768), swBid, new InetSocketAddress(Inet4Address.getByName("127.0.1.2"), 32768));
SwitchDescription ofSwitchDescription = new SwitchDescription(switchDescription.getManufacturer(), switchDescription.getHardware(), switchDescription.getSoftware(), switchDescription.getSerialNumber(), switchDescription.getDatapath());
OFFactoryVer13 ofFactory = new OFFactoryVer13();
InetSocketAddress switchSocketAddress = new InetSocketAddress(Inet4Address.getByName("127.0.1.1"), 32768);
for (DatapathId swId : switches.keySet()) {
IOFSwitch sw = switches.get(swId);
expect(sw.getOFFactory()).andStubReturn(ofFactory);
expect(sw.isActive()).andReturn(true).anyTimes();
expect(sw.getId()).andReturn(swId).anyTimes();
expect(sw.getSwitchDescription()).andReturn(ofSwitchDescription);
expect(sw.getInetAddress()).andReturn(switchAddresses.get(swId));
expect(sw.getControllerRole()).andStubReturn(OFControllerRole.ROLE_EQUAL);
OFConnection connect = createMock(OFConnection.class);
expect(connect.getRemoteInetAddress()).andReturn(switchSocketAddress);
expect(sw.getConnectionByCategory(eq(LogicalOFMessageCategory.MAIN))).andReturn(connect);
}
expect(switchManager.getAllSwitchMap(true)).andReturn(switches);
expect(switchManager.getPhysicalPorts(eq(iofSwitch1))).andReturn(ImmutableList.of(makePhysicalPortMock(1, true), makePhysicalPortMock(2, true)));
expect(switchManager.getPhysicalPorts(eq(iofSwitch2))).andReturn(ImmutableList.of(makePhysicalPortMock(3, true), makePhysicalPortMock(4, true), makePhysicalPortMock(5, false)));
expect(featureDetector.detectSwitch(iofSwitch1)).andReturn(ImmutableSet.of(SwitchFeature.METERS));
expect(featureDetector.detectSwitch(iofSwitch2)).andReturn(ImmutableSet.of(SwitchFeature.METERS, SwitchFeature.BFD));
ArrayList<Message> producedMessages = new ArrayList<>();
// setup hook for verify that we create new message for producer
producerService.sendMessageAndTrack(eq(KAFKA_ISL_DISCOVERY_TOPIC), anyObject(), anyObject(InfoMessage.class));
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() {
Message sentMessage = (Message) getCurrentArguments()[2];
sentMessage.setTimestamp(0);
producedMessages.add(sentMessage);
return null;
}
}).anyTimes();
replayAll();
String correlationId = "unit-test-correlation-id";
String dumpId = "dummy-dump-id";
try (CorrelationContextClosable dummy = CorrelationContext.create(correlationId)) {
service.dumpAllSwitches(dumpId);
}
verify(producerService);
ArrayList<Message> expectedMessages = new ArrayList<>();
expectedMessages.add(new InfoMessage(new NetworkDumpSwitchData(new SpeakerSwitchView(new SwitchId(swAid.getLong()), new IpSocketAddress("127.0.1.1", 32768), new IpSocketAddress("127.0.1.254", 6653), "127.0.1.1", "OF_13", switchDescription, ImmutableSet.of(SwitchFeature.METERS), ImmutableList.of(new SpeakerSwitchPortView(1, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(2, SpeakerSwitchPortView.State.UP))), dumpId, true), 0, correlationId));
expectedMessages.add(new InfoMessage(new NetworkDumpSwitchData(new SpeakerSwitchView(new SwitchId(swBid.getLong()), new IpSocketAddress("127.0.1.2", 32768), new IpSocketAddress("127.0.1.254", 6653), "127.0.1.2", "OF_13", switchDescription, ImmutableSet.of(SwitchFeature.METERS, SwitchFeature.BFD), ImmutableList.of(new SpeakerSwitchPortView(3, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(4, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(5, SpeakerSwitchPortView.State.DOWN))), dumpId, true), 0, correlationId));
assertEquals(expectedMessages, producedMessages);
}
use of org.openkilda.messaging.info.discovery.NetworkDumpSwitchData in project open-kilda by telstra.
the class SwitchMonitorBolt method handleNetworkUpdateNotification.
private void handleNetworkUpdateNotification(Tuple input) throws PipelineException {
String region = pullRegion(input);
InfoData payload = pullValue(input, SpeakerToNetworkProxyBolt.FIELD_ID_PAYLOAD, InfoData.class);
if (payload instanceof SwitchInfoData) {
service.handleStatusUpdateNotification((SwitchInfoData) payload, region);
} else if (payload instanceof NetworkDumpSwitchData) {
service.handleNetworkDumpResponse((NetworkDumpSwitchData) payload, region);
} else if (payload instanceof PortInfoData) {
service.handlePortStatusUpdateNotification((PortInfoData) payload, region);
} else {
unhandledInput(input);
}
}
use of org.openkilda.messaging.info.discovery.NetworkDumpSwitchData in project open-kilda by telstra.
the class SwitchMonitorServiceTest method testLosePassiveRegion.
@Test
public void testLosePassiveRegion() {
SwitchMonitorService subject = makeSubject();
Instant t0 = clock.instant();
SwitchId targetSw = SWITCH_ALPHA;
makeConnectInRegions(subject, targetSw, REGION_ALPHA, REGION_BETA);
clock.adjust(Duration.ofSeconds(1));
subject.handleRegionOfflineNotification(REGION_BETA);
SpeakerSwitchView suggestedAlphaSpeakerData = makeSwitchActivateNotification(targetSw, 1).getSwitchView();
verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(targetSw), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(suggestedAlphaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedAlphaSpeakerData.getSpeakerSocketAddress()).build()).build(), arg)));
verifyNoMoreInteractions(carrier);
reset(carrier);
clock.adjust(Duration.ofSeconds(1));
Instant t1 = clock.instant();
SpeakerSwitchView suggestedBetaSpeakerData = makeSwitchActivateNotification(targetSw, 2).getSwitchView();
NetworkDumpSwitchData dumpBeta = new NetworkDumpSwitchData(suggestedBetaSpeakerData, NETWORK_DUMP_CORRELATION_ID, true);
subject.handleNetworkDumpResponse(dumpBeta, REGION_BETA);
verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(targetSw), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(suggestedAlphaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedAlphaSpeakerData.getSpeakerSocketAddress()).build()).connection(SwitchAvailabilityEntry.builder().regionName(REGION_BETA).connectMode(SwitchConnectMode.READ_WRITE).master(false).connectedAt(t1).switchAddress(suggestedBetaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedBetaSpeakerData.getSpeakerSocketAddress()).build()).build(), arg)));
verifyNoMoreInteractions(carrier);
}
Aggregations