use of org.openkilda.model.IpSocketAddress in project open-kilda by telstra.
the class SwitchTest method serializeLoop.
@Test
public void serializeLoop() throws Exception {
Switch origin = Switch.builder().switchId(new SwitchId(1)).controller("test_controller").description("test_description").hostname("test_hostname").pop("test_pop").status(SwitchStatus.ACTIVE).underMaintenance(true).socketAddress(new IpSocketAddress("192.168.10.20", 1)).features(Collections.singleton(SwitchFeature.GROUP_PACKET_OUT_CONTROLLER)).build();
serializer.serialize(origin);
Switch reconstructed = (Switch) serializer.deserialize();
Assert.assertEquals(origin, reconstructed);
}
use of org.openkilda.model.IpSocketAddress 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.model.IpSocketAddress in project open-kilda by telstra.
the class NetworkIntegrationTest method switchAdd.
@Test
@Ignore
public void switchAdd() {
Set<SwitchFeature> features = new HashSet<>();
features.add(SwitchFeature.BFD);
Integer bfdLocalPortOffset = options.getBfdLogicalPortOffset();
List<SpeakerSwitchPortView> ports = ImmutableList.of(new SpeakerSwitchPortView(1, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(1 + bfdLocalPortOffset, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(2, SpeakerSwitchPortView.State.DOWN), new SpeakerSwitchPortView(2 + bfdLocalPortOffset, SpeakerSwitchPortView.State.DOWN));
SpeakerSwitchView speakerSwitchView = new SpeakerSwitchView(alphaDatapath, new IpSocketAddress(alphaInetAddress.getHostString(), alphaInetAddress.getPort()), new IpSocketAddress(speakerInetAddress.getHostString(), speakerInetAddress.getPort()), alphaInetAddress.getHostString(), "OF_13", switchDescription, features, ports);
NetworkSwitchService switchService = integrationCarrier.getSwitchService();
SwitchInfoData switchAddEvent = new SwitchInfoData(alphaDatapath, SwitchChangeType.ADDED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView);
switchService.switchEvent(switchAddEvent);
SwitchInfoData switchActivateEvent = new SwitchInfoData(alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView);
switchService.switchEvent(switchActivateEvent);
}
use of org.openkilda.model.IpSocketAddress in project open-kilda by telstra.
the class SwitchMonitorServiceTest method makeSwitchActivateNotification.
private SwitchInfoData makeSwitchActivateNotification(SwitchId switchId, int network) {
String swAddress = String.format("127.0.%d.2", network);
SpeakerSwitchView speakerView = SpeakerSwitchView.builder().datapath(switchId).switchSocketAddress(new IpSocketAddress(swAddress, 32769)).speakerSocketAddress(new IpSocketAddress(String.format("127.0.%d.1", network), 6653)).ofVersion("OF_13").description(SpeakerSwitchDescription.builder().manufacturer("manufacturer").hardware("hardware").software("software").serialNumber("1").datapath(switchId.toString()).build()).features(Collections.emptySet()).port(SpeakerSwitchPortView.builder().number(1).state(State.UP).build()).port(SpeakerSwitchPortView.builder().number(2).state(State.DOWN).build()).build();
return new SwitchInfoData(SWITCH_ALPHA, SwitchChangeType.ACTIVATED, swAddress, String.format("%s %s %s", speakerView.getDescription().getManufacturer(), speakerView.getOfVersion(), speakerView.getDescription().getSoftware()), "controller", false, speakerView);
}
use of org.openkilda.model.IpSocketAddress in project open-kilda by telstra.
the class SwitchMonitor method makeSwitchConnect.
private SwitchConnect makeSwitchConnect(boolean isActive, SpeakerSwitchView speakerData) {
IpSocketAddress switchAddress = null;
IpSocketAddress speakerAddress = null;
if (speakerData != null) {
switchAddress = speakerData.getSwitchSocketAddress();
speakerAddress = speakerData.getSpeakerSocketAddress();
}
return new SwitchConnect(isActive, clock.instant(), switchAddress, speakerAddress);
}
Aggregations