Search in sources :

Example 6 with OFPortDesc

use of org.projectfloodlight.openflow.protocol.OFPortDesc in project open-kilda by telstra.

the class PathVerificationService method getSwitchPortSpeed.

private long getSwitchPortSpeed(IOFSwitch sw, OFPort inPort) {
    OFPortDesc port = sw.getPort(inPort);
    long speed = -1;
    if (port.getVersion().compareTo(OFVersion.OF_13) > 0) {
        for (OFPortDescProp prop : port.getProperties()) {
            if (prop.getType() == 0) {
                speed = ((OFPortDescPropEthernet) prop).getCurrSpeed();
                break;
            }
        }
    }
    if (speed < 0) {
        speed = port.getCurrSpeed();
    }
    return speed;
}
Also used : OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) OFPortDescProp(org.projectfloodlight.openflow.protocol.OFPortDescProp)

Example 7 with OFPortDesc

use of org.projectfloodlight.openflow.protocol.OFPortDesc in project open-kilda by telstra.

the class RecordHandler method doPortsCommandDataRequest.

private void doPortsCommandDataRequest(Set<SwitchId> scope, PortsCommandData payload, String correlationId) {
    ISwitchManager switchManager = context.getModuleContext().getServiceImpl(ISwitchManager.class);
    try {
        logger.info("Getting ports data. Requester: {}", payload.getRequester());
        Map<DatapathId, IOFSwitch> allSwitchMap = context.getSwitchManager().getAllSwitchMap(true);
        for (Map.Entry<DatapathId, IOFSwitch> entry : allSwitchMap.entrySet()) {
            SwitchId switchId = new SwitchId(entry.getKey().toString());
            if (!scope.contains(switchId)) {
                continue;
            }
            try {
                IOFSwitch sw = entry.getValue();
                Set<PortStatusData> statuses = new HashSet<>();
                for (OFPortDesc portDesc : switchManager.getPhysicalPorts(sw.getId())) {
                    statuses.add(new PortStatusData(portDesc.getPortNo().getPortNumber(), portDesc.isEnabled() ? PortStatus.UP : PortStatus.DOWN));
                }
                SwitchPortStatusData response = SwitchPortStatusData.builder().switchId(switchId).ports(statuses).requester(payload.getRequester()).build();
                InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
                getKafkaProducer().sendMessageAndTrack(context.getKafkaStatsTopic(), infoMessage);
            } catch (Exception e) {
                logger.error("Could not get port stats data for switch '{}' with error '{}'", switchId, e.getMessage(), e);
            }
        }
    } catch (Exception e) {
        logger.error("Could not get port data for stats '{}'", e.getMessage(), e);
    }
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) SwitchPortStatusData(org.openkilda.messaging.info.stats.SwitchPortStatusData) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchId(org.openkilda.model.SwitchId) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException) IOException(java.io.IOException) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) OfInstallException(org.openkilda.floodlight.error.OfInstallException) FlowCommandException(org.openkilda.floodlight.error.FlowCommandException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) PortStatusData(org.openkilda.messaging.info.stats.PortStatusData) SwitchPortStatusData(org.openkilda.messaging.info.stats.SwitchPortStatusData) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) InfoMessage(org.openkilda.messaging.info.InfoMessage) Map(java.util.Map) HashSet(java.util.HashSet)

Example 8 with OFPortDesc

use of org.projectfloodlight.openflow.protocol.OFPortDesc in project open-kilda by telstra.

the class RecordHandlerTest method networkDumpTest.

/**
 * Simple TDD test that was used to develop warming mechanism for OFELinkBolt. We create
 * command and put it to KafkaMessageCollector then mock ISwitchManager::getAllSwitchMap and
 * verify that output message comes to producer.
 */
@Test
public void networkDumpTest() {
    // 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);
    Map<DatapathId, IOFSwitch> switches = ImmutableMap.of(DatapathId.of(1), iofSwitch1, DatapathId.of(2), iofSwitch2);
    for (DatapathId swId : switches.keySet()) {
        IOFSwitch sw = switches.get(swId);
        expect(sw.isActive()).andReturn(true).anyTimes();
        expect(sw.getId()).andReturn(swId).anyTimes();
    }
    expect(switchManager.getAllSwitchMap()).andReturn(switches);
    // ports for OFSwitch::getEnabledPorts
    OFPortDesc ofPortDesc1 = mock(OFPortDesc.class);
    OFPortDesc ofPortDesc2 = mock(OFPortDesc.class);
    OFPortDesc ofPortDesc3 = mock(OFPortDesc.class);
    OFPortDesc ofPortDesc4 = mock(OFPortDesc.class);
    expect(ofPortDesc1.getPortNo()).andReturn(OFPort.ofInt(1));
    expect(ofPortDesc2.getPortNo()).andReturn(OFPort.ofInt(2));
    expect(ofPortDesc3.getPortNo()).andReturn(OFPort.ofInt(3));
    expect(ofPortDesc4.getPortNo()).andReturn(OFPort.ofInt(4));
    expect(iofSwitch1.getEnabledPorts()).andReturn(ImmutableList.of(ofPortDesc1, ofPortDesc2));
    expect(iofSwitch2.getEnabledPorts()).andReturn(ImmutableList.of(ofPortDesc3, ofPortDesc4));
    // Logic in SwitchEventCollector.buildSwitchInfoData is too complicated and requires a lot
    // of mocking code so I replaced it with mock on kafkaMessageCollector.buildSwitchInfoData
    handler.overrideSwitchInfoData(DatapathId.of(1), new SwitchInfoData("sw1", SwitchState.ADDED, "127.0.0.1", "localhost", "test switch", "kilda"));
    handler.overrideSwitchInfoData(DatapathId.of(2), new SwitchInfoData("sw2", SwitchState.ADDED, "127.0.0.1", "localhost", "test switch", "kilda"));
    // setup hook for verify that we create new message for producer
    producer.postMessage(eq(OUTPUT_DISCO_TOPIC), anyObject(InfoMessage.class));
    replayAll();
    // Create CommandMessage with NetworkCommandData for trigger network dump
    CommandMessage command = new CommandMessage(new NetworkCommandData(), System.currentTimeMillis(), Utils.SYSTEM_CORRELATION_ID, Destination.CONTROLLER);
    // KafkaMessageCollector contains a complicated run logic with couple nested private
    // classes, threading and that is very painful for writing clear looking test code so I
    // created the simple method in KafkaMessageCollector for simplifying test logic.
    handler.handleMessage(command);
    verify(producer);
// TODO: verify content of InfoMessage in producer.postMessage
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) InfoMessage(org.openkilda.messaging.info.InfoMessage) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFSwitch(net.floodlightcontroller.core.internal.OFSwitch) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) CommandMessage(org.openkilda.messaging.command.CommandMessage) Test(org.junit.Test)

Example 9 with OFPortDesc

use of org.projectfloodlight.openflow.protocol.OFPortDesc 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)

Example 10 with OFPortDesc

use of org.projectfloodlight.openflow.protocol.OFPortDesc in project open-kilda by telstra.

the class SwitchTrackingServiceTest method makePhysicalPortMock.

private OFPortDesc makePhysicalPortMock(int number, boolean isEnabled) {
    OFPortDesc port = createMock(OFPortDesc.class);
    expect(port.getPortNo()).andReturn(OFPort.of(number)).anyTimes();
    expect(port.isEnabled()).andReturn(isEnabled).anyTimes();
    return port;
}
Also used : OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc)

Aggregations

OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)11 InetSocketAddress (java.net.InetSocketAddress)5 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)4 DatapathId (org.projectfloodlight.openflow.types.DatapathId)4 FloodlightModuleContext (net.floodlightcontroller.core.module.FloodlightModuleContext)3 Before (org.junit.Before)3 InfoMessage (org.openkilda.messaging.info.InfoMessage)3 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ByteBuffer (java.nio.ByteBuffer)2 Map (java.util.Map)2 FloodlightModuleException (net.floodlightcontroller.core.module.FloodlightModuleException)2 Ethernet (net.floodlightcontroller.packet.Ethernet)2 LLDPTLV (net.floodlightcontroller.packet.LLDPTLV)2 Test (org.junit.Test)2 OFDescStatsReply (org.projectfloodlight.openflow.protocol.OFDescStatsReply)2 OFPortDescProp (org.projectfloodlight.openflow.protocol.OFPortDescProp)2 OFPortDescPropEthernet (org.projectfloodlight.openflow.protocol.OFPortDescPropEthernet)2 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)1