Search in sources :

Example 6 with SpeakerSwitchPortView

use of org.openkilda.messaging.model.SpeakerSwitchPortView in project open-kilda by telstra.

the class NetworkSwitchServiceTest method newSwitch.

@Test
public void newSwitch() {
    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);
    NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
    service.switchEvent(switchAddEvent);
    verifySwitchSync(service);
    // System.out.println(mockingDetails(carrier).printInvocations());
    // System.out.println(mockingDetails(switchRepository).printInvocations());
    verifyNewSwitchAfterSwitchSync(ports);
}
Also used : SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test)

Example 7 with SpeakerSwitchPortView

use of org.openkilda.messaging.model.SpeakerSwitchPortView in project open-kilda by telstra.

the class NetworkSwitchServiceTest method doSpeakerOnline.

private List<SpeakerSwitchPortView> doSpeakerOnline(NetworkSwitchService service, Set<SwitchFeature> features) {
    List<SpeakerSwitchPortView> ports = getSpeakerSwitchPortViews();
    SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder().features(features).ports(ports).build();
    SwitchInfoData switchAddEvent = new SwitchInfoData(alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView);
    service.switchEvent(switchAddEvent);
    verifySwitchSync(service);
    return ports;
}
Also used : SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 8 with SpeakerSwitchPortView

use of org.openkilda.messaging.model.SpeakerSwitchPortView in project open-kilda by telstra.

the class SwitchTrackingService method buildSwitch.

private SpeakerSwitchView buildSwitch(IOFSwitch sw) throws InvalidConnectionDataException {
    SpeakerSwitchView.SpeakerSwitchViewBuilder builder = SpeakerSwitchView.builder().datapath(new SwitchId(sw.getId().getLong())).hostname(readHostname(sw.getInetAddress())).ofVersion(sw.getOFFactory().getVersion().toString()).features(featureDetector.detectSwitch(sw));
    SwitchDescription ofDescription = sw.getSwitchDescription();
    builder.description(SpeakerSwitchDescription.builder().manufacturer(ofDescription.getManufacturerDescription()).hardware(ofDescription.getHardwareDescription()).software(ofDescription.getSoftwareDescription()).serialNumber(ofDescription.getSerialNumber()).datapath(ofDescription.getDatapathDescription()).build());
    switchManager.getPhysicalPorts(sw).stream().map(port -> new SpeakerSwitchPortView(port.getPortNo().getPortNumber(), port.isEnabled() ? SpeakerSwitchPortView.State.UP : SpeakerSwitchPortView.State.DOWN)).forEach(builder::port);
    buildSwitchAddress(builder, sw);
    buildSwitchSpeakerAddress(builder, sw);
    return builder.build();
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) OFControllerRole(org.projectfloodlight.openflow.protocol.OFControllerRole) Message(org.openkilda.messaging.Message) OfPortDescConverter(org.openkilda.floodlight.converter.OfPortDescConverter) SocketAddress(java.net.SocketAddress) LogicalOFMessageCategory(net.floodlightcontroller.core.LogicalOFMessageCategory) SwitchChangeType(org.openkilda.messaging.info.event.SwitchChangeType) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) LoggerFactory(org.slf4j.LoggerFactory) FloodlightDashboardLogger(org.openkilda.floodlight.utils.FloodlightDashboardLogger) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) IService(org.openkilda.floodlight.service.IService) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) IOFSwitchService(net.floodlightcontroller.core.internal.IOFSwitchService) InetAddress(java.net.InetAddress) SpeakerSwitchDescription(org.openkilda.messaging.model.SpeakerSwitchDescription) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData) IpSocketAddress(org.openkilda.model.IpSocketAddress) Logger(org.slf4j.Logger) Collection(java.util.Collection) PortChangeType(net.floodlightcontroller.core.PortChangeType) InfoData(org.openkilda.messaging.info.InfoData) FloodlightModuleContext(net.floodlightcontroller.core.module.FloodlightModuleContext) IofSwitchConverter(org.openkilda.floodlight.converter.IofSwitchConverter) FeatureDetectorService(org.openkilda.floodlight.service.FeatureDetectorService) InetSocketAddress(java.net.InetSocketAddress) CorrelationContext(org.openkilda.floodlight.utils.CorrelationContext) Slf4j(lombok.extern.slf4j.Slf4j) KafkaUtilityService(org.openkilda.floodlight.service.kafka.KafkaUtilityService) NewCorrelationContextRequired(org.openkilda.floodlight.utils.NewCorrelationContextRequired) KafkaChannel(org.openkilda.floodlight.KafkaChannel) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) SwitchId(org.openkilda.model.SwitchId) IOFSwitchListener(net.floodlightcontroller.core.IOFSwitchListener) DatapathId(org.projectfloodlight.openflow.types.DatapathId) InvalidConnectionDataException(org.openkilda.floodlight.error.InvalidConnectionDataException) SwitchDescription(net.floodlightcontroller.core.SwitchDescription) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchId(org.openkilda.model.SwitchId) SpeakerSwitchDescription(org.openkilda.messaging.model.SpeakerSwitchDescription) SwitchDescription(net.floodlightcontroller.core.SwitchDescription)

Example 9 with SpeakerSwitchPortView

use of org.openkilda.messaging.model.SpeakerSwitchPortView 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);
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFConnection(net.floodlightcontroller.core.internal.OFConnection) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) CorrelationContextClosable(org.openkilda.floodlight.utils.CorrelationContext.CorrelationContextClosable) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchId(org.openkilda.model.SwitchId) IpSocketAddress(org.openkilda.model.IpSocketAddress) IAnswer(org.easymock.IAnswer) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) InfoMessage(org.openkilda.messaging.info.InfoMessage) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFSwitch(net.floodlightcontroller.core.internal.OFSwitch) SpeakerSwitchDescription(org.openkilda.messaging.model.SpeakerSwitchDescription) SwitchDescription(net.floodlightcontroller.core.SwitchDescription) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData) Test(org.junit.Test)

Example 10 with SpeakerSwitchPortView

use of org.openkilda.messaging.model.SpeakerSwitchPortView in project open-kilda by telstra.

the class SwitchTrackingServiceTest method prepareAliveSwitchEvent.

private Capture<Message> prepareAliveSwitchEvent(SpeakerSwitchView switchView) throws Exception {
    IOFSwitch sw = createMock(IOFSwitch.class);
    expect(sw.getId()).andReturn(dpId).anyTimes();
    expect(sw.getInetAddress()).andReturn(new InetSocketAddress("127.0.1.1", 32768)).times(2);
    OFConnection connect = createMock(OFConnection.class);
    expect(connect.getRemoteInetAddress()).andReturn(new InetSocketAddress("127.0.1.254", 6653)).times(2);
    expect(sw.getConnectionByCategory(eq(LogicalOFMessageCategory.MAIN))).andReturn(connect).times(2);
    SwitchDescription description = createMock(SwitchDescription.class);
    expect(description.getManufacturerDescription()).andReturn("(mock) getManufacturerDescription()").times(2);
    expect(description.getHardwareDescription()).andReturn("(mock) getHardwareDescription()");
    expect(description.getSoftwareDescription()).andReturn("(mock) getSoftwareDescription()").times(2);
    expect(description.getSerialNumber()).andReturn("(mock) getSerialNumber()");
    expect(description.getDatapathDescription()).andReturn("(mock) getDatapathDescription()");
    expect(sw.getSwitchDescription()).andReturn(description).times(3);
    expect(sw.getOFFactory()).andStubReturn(new OFFactoryVer13());
    expect(switchManager.lookupSwitch(eq(dpId))).andReturn(sw);
    List<OFPortDesc> physicalPorts = new ArrayList<>(switchView.getPorts().size());
    int idx = 1;
    for (SpeakerSwitchPortView port : switchView.getPorts()) {
        physicalPorts.add(makePhysicalPortMock(idx++, port.getState() == SpeakerSwitchPortView.State.UP));
    }
    expect(switchManager.getPhysicalPorts(sw)).andReturn(physicalPorts);
    expect(featureDetector.detectSwitch(sw)).andReturn(ImmutableSet.of(SwitchFeature.METERS));
    return prepareSwitchEventCommon(dpId);
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFConnection(net.floodlightcontroller.core.internal.OFConnection) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) SpeakerSwitchDescription(org.openkilda.messaging.model.SpeakerSwitchDescription) SwitchDescription(net.floodlightcontroller.core.SwitchDescription)

Aggregations

SpeakerSwitchPortView (org.openkilda.messaging.model.SpeakerSwitchPortView)20 SpeakerSwitchView (org.openkilda.messaging.model.SpeakerSwitchView)17 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)16 Test (org.junit.Test)15 InetSocketAddress (java.net.InetSocketAddress)3 ArrayList (java.util.ArrayList)3 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)3 SwitchDescription (net.floodlightcontroller.core.SwitchDescription)3 GroupSyncEntry (org.openkilda.messaging.info.switches.GroupSyncEntry)3 RulesSyncEntry (org.openkilda.messaging.info.switches.RulesSyncEntry)3 SwitchSyncResponse (org.openkilda.messaging.info.switches.SwitchSyncResponse)3 SpeakerSwitchDescription (org.openkilda.messaging.model.SpeakerSwitchDescription)3 IpSocketAddress (org.openkilda.model.IpSocketAddress)3 HashSet (java.util.HashSet)2 OFConnection (net.floodlightcontroller.core.internal.OFConnection)2 Message (org.openkilda.messaging.Message)2 SwitchSyncErrorData (org.openkilda.messaging.error.rule.SwitchSyncErrorData)2 InfoMessage (org.openkilda.messaging.info.InfoMessage)2 NetworkDumpSwitchData (org.openkilda.messaging.info.discovery.NetworkDumpSwitchData)2 PortInfoData (org.openkilda.messaging.info.event.PortInfoData)2