Search in sources :

Example 1 with PortGrouping

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping in project openflowplugin by opendaylight.

the class OF10DeviceInitializer method writePhyPortInformation.

@SuppressWarnings("checkstyle:IllegalCatch")
private static void writePhyPortInformation(final DeviceContext deviceContext) {
    final DeviceInfo deviceInfo = deviceContext.getDeviceInfo();
    final ConnectionContext connectionContext = deviceContext.getPrimaryConnectionContext();
    final MessageTranslator<PortGrouping, FlowCapableNodeConnector> translator = deviceContext.oook().lookupTranslator(new TranslatorKey(deviceInfo.getVersion(), PortGrouping.class.getName()));
    connectionContext.getFeatures().getPhyPort().forEach(port -> {
        final NodeConnectorId nodeConnectorId = InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(deviceInfo.getDatapathId(), port.getPortNo(), OpenflowVersion.get(deviceInfo.getVersion()));
        try {
            deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, deviceInfo.getNodeInstanceIdentifier().child(NodeConnector.class, new NodeConnectorKey(nodeConnectorId)), new NodeConnectorBuilder().setId(nodeConnectorId).addAugmentation(FlowCapableNodeConnector.class, translator.translate(port, deviceInfo, null)).addAugmentation(FlowCapableNodeConnectorStatisticsData.class, new FlowCapableNodeConnectorStatisticsDataBuilder().build()).build());
        } catch (final Exception e) {
            LOG.debug("Failed to write node {} to DS ", deviceInfo, e);
        }
    });
}
Also used : FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) NodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) FlowCapableNodeConnectorStatisticsDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) NodeConnectorBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) PortGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping) TranslatorKey(org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey)

Example 2 with PortGrouping

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping in project openflowplugin by opendaylight.

the class PortTranslatorUtilTest method mockPortGrouping.

private PortGrouping mockPortGrouping() {
    PortGrouping portGrouping = mock(PortGrouping.class);
    when(portGrouping.getAdvertisedFeatures()).thenReturn(getPortFeatures());
    when(portGrouping.getAdvertisedFeaturesV10()).thenReturn(getPortFeaturesV10());
    when(portGrouping.getConfig()).thenReturn(getPortConfig());
    when(portGrouping.getConfigV10()).thenReturn(getPortConfigV10());
    when(portGrouping.getCurrentFeatures()).thenReturn(getPortFeatures());
    when(portGrouping.getCurrentFeaturesV10()).thenReturn(getPortFeaturesV10());
    when(portGrouping.getCurrSpeed()).thenReturn(currentSpeed);
    when(portGrouping.getHwAddr()).thenReturn(getMacAddress());
    when(portGrouping.getName()).thenReturn(NAME);
    when(portGrouping.getMaxSpeed()).thenReturn(MAX_SPEED);
    when(portGrouping.getPeerFeatures()).thenReturn(getPortFeatures());
    when(portGrouping.getPeerFeaturesV10()).thenReturn(getPortFeaturesV10());
    when(portGrouping.getPortNo()).thenReturn(Long.MAX_VALUE);
    when(portGrouping.getState()).thenReturn(getPortState());
    when(portGrouping.getSupportedFeatures()).thenReturn(getPortFeatures());
    when(portGrouping.getSupportedFeaturesV10()).thenReturn(getPortFeaturesV10());
    return portGrouping;
}
Also used : PortGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping)

Example 3 with PortGrouping

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping in project openflowplugin by opendaylight.

the class PortTranslatorUtilTest method testTranslatePort.

/**
 * Test  method for
 * {@link PortTranslatorUtil#translatePort(Short, java.math.BigInteger,
 * Long, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping)} ()}.
 */
@Test
public void testTranslatePort() {
    Short version = OpenflowVersion.OF10.getVersion();
    BigInteger dataPathId = BigInteger.ONE;
    Long portNumber = Long.MAX_VALUE;
    PortGrouping portGrouping = mockPortGrouping();
    NodeConnectorUpdated nodeConnectorUpdated = PortTranslatorUtil.translatePort(version, dataPathId, portNumber, portGrouping);
    assertNotNull(nodeConnectorUpdated);
    version = OpenflowVersion.OF13.getVersion();
    nodeConnectorUpdated = PortTranslatorUtil.translatePort(version, dataPathId, portNumber, portGrouping);
    assertNotNull(nodeConnectorUpdated);
    version = OpenflowVersion.UNSUPPORTED.getVersion();
    nodeConnectorUpdated = PortTranslatorUtil.translatePort(version, dataPathId, portNumber, portGrouping);
    assertNotNull(nodeConnectorUpdated);
}
Also used : PortGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping) BigInteger(java.math.BigInteger) NodeConnectorUpdated(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated) Test(org.junit.Test)

Example 4 with PortGrouping

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping in project openflowplugin by opendaylight.

the class PortTranslatorUtil method translatePort.

public static NodeConnectorUpdated translatePort(final Short version, final BigInteger datapathId, final Long portNumber, final PortGrouping port) {
    OpenflowVersion ofVersion = OpenflowVersion.get(version);
    final NodeConnectorUpdatedBuilder builder = InventoryDataServiceUtil.nodeConnectorUpdatedBuilderFromDatapathIdPortNo(datapathId, port.getPortNo(), ofVersion);
    FlowCapableNodeConnectorUpdatedBuilder fcncub = new FlowCapableNodeConnectorUpdatedBuilder();
    if (ofVersion == OpenflowVersion.OF13) {
        fcncub.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(port.getAdvertisedFeatures()));
        fcncub.setConfiguration(PortTranslatorUtil.translatePortConfig(port.getConfig()));
        fcncub.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(port.getCurrentFeatures()));
        fcncub.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(port.getPeerFeatures()));
        fcncub.setState(PortTranslatorUtil.translatePortState(port.getState()));
        fcncub.setSupported(PortTranslatorUtil.translatePortFeatures(port.getSupportedFeatures()));
    } else if (ofVersion == OpenflowVersion.OF10) {
        fcncub.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(port.getAdvertisedFeaturesV10()));
        fcncub.setConfiguration(PortTranslatorUtil.translatePortConfig(port.getConfigV10()));
        fcncub.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(port.getCurrentFeaturesV10()));
        fcncub.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(port.getPeerFeaturesV10()));
        fcncub.setState(PortTranslatorUtil.translatePortState(port.getStateV10()));
        fcncub.setSupported(PortTranslatorUtil.translatePortFeatures(port.getSupportedFeaturesV10()));
    }
    if (port instanceof PortStatusMessage) {
        if (((PortStatusMessage) port).getReason() != null) {
            fcncub.setReason(PortReason.forValue(((PortStatusMessage) port).getReason().getIntValue()));
        } else {
            LOG.debug("PortStatus Message has reason as null");
        }
    }
    fcncub.setCurrentSpeed(port.getCurrSpeed());
    fcncub.setHardwareAddress(port.getHwAddr());
    fcncub.setMaximumSpeed(port.getMaxSpeed());
    fcncub.setName(port.getName());
    fcncub.setPortNumber(OpenflowPortsUtil.getProtocolAgnosticPort(ofVersion, portNumber));
    builder.addAugmentation(FlowCapableNodeConnectorUpdated.class, fcncub.build());
    return builder.build();
}
Also used : OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) PortStatusMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage) FlowCapableNodeConnectorUpdatedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdatedBuilder) NodeConnectorUpdatedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdatedBuilder) FlowCapableNodeConnectorUpdatedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdatedBuilder)

Example 5 with PortGrouping

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping in project openflowplugin by opendaylight.

the class PortUpdateTranslator method translate.

@Override
public FlowCapableNodeConnector translate(final PortGrouping input, final DeviceInfo deviceInfo, final Object connectionDistinguisher) {
    final FlowCapableNodeConnectorBuilder builder = new FlowCapableNodeConnectorBuilder();
    // OF1.0
    if (deviceInfo.getVersion() == OFConstants.OFP_VERSION_1_0) {
        builder.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(input.getAdvertisedFeaturesV10()));
        builder.setConfiguration(PortTranslatorUtil.translatePortConfig(input.getConfigV10()));
        builder.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(input.getCurrentFeaturesV10()));
        builder.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(input.getPeerFeaturesV10()));
        builder.setState(PortTranslatorUtil.translatePortState(input.getStateV10()));
        builder.setSupported(PortTranslatorUtil.translatePortFeatures(input.getSupportedFeaturesV10()));
    } else if (deviceInfo.getVersion() == OFConstants.OFP_VERSION_1_3) {
        builder.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(input.getAdvertisedFeatures()));
        builder.setConfiguration(PortTranslatorUtil.translatePortConfig(input.getConfig()));
        builder.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(input.getCurrentFeatures()));
        builder.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(input.getPeerFeatures()));
        builder.setState(PortTranslatorUtil.translatePortState(input.getState()));
        builder.setSupported(PortTranslatorUtil.translatePortFeatures(input.getSupportedFeatures()));
        builder.setQueue(Collections.<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue>emptyList());
    }
    if (input instanceof PortStatusMessage) {
        if (((PortStatusMessage) input).getReason() != null) {
            builder.setReason(PortReason.forValue(((PortStatusMessage) input).getReason().getIntValue()));
        } else {
            LOG.debug("PortStatus Message has reason as null");
        }
    }
    builder.setCurrentSpeed(input.getCurrSpeed());
    builder.setHardwareAddress(input.getHwAddr());
    builder.setMaximumSpeed(input.getMaxSpeed());
    builder.setName(input.getName());
    builder.setPortNumber(new PortNumberUni(input.getPortNo()));
    return builder.build();
}
Also used : FlowCapableNodeConnectorBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder) PortStatusMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage) PortNumberUni(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni)

Aggregations

PortGrouping (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping)3 OpenflowVersion (org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion)2 PortStatusMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)2 BigInteger (java.math.BigInteger)1 Test (org.junit.Test)1 ConnectionContext (org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext)1 DeviceInfo (org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo)1 TranslatorKey (org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey)1 FlowCapableNodeConnector (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector)1 FlowCapableNodeConnectorBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder)1 FlowCapableNodeConnectorUpdatedBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdatedBuilder)1 PortNumberUni (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni)1 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)1 NodeConnectorRemovedBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemovedBuilder)1 NodeConnectorUpdated (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated)1 NodeConnectorUpdatedBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdatedBuilder)1 NodeConnector (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector)1 NodeConnectorBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder)1 NodeConnectorKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey)1 FlowCapableNodeConnectorStatisticsDataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder)1