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);
}
});
}
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;
}
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);
}
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();
}
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();
}
Aggregations