use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder in project netvirt by opendaylight.
the class NeutronFloatingToFixedIpMappingChangeListener method addToFloatingIpInfo.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void addToFloatingIpInfo(String routerName, Uuid extNetworkId, String fixedNeutronPortName, String fixedIpAddress, String floatingIpAddress, Uuid floatingIpId) {
RouterPortsBuilder routerPortsBuilder;
InstanceIdentifier<RouterPorts> routerPortsIdentifier = InstanceIdentifier.builder(FloatingIpInfo.class).child(RouterPorts.class, new RouterPortsKey(routerName)).build();
try {
Optional<RouterPorts> optionalRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier);
if (optionalRouterPorts.isPresent()) {
LOG.debug("Updating routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
routerPortsBuilder = new RouterPortsBuilder(optionalRouterPorts.get());
} else {
LOG.debug("Creating new routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
routerPortsBuilder = new RouterPortsBuilder().withKey(new RouterPortsKey(routerName)).setRouterId(routerName);
}
if (extNetworkId != null) {
routerPortsBuilder.setExternalNetworkId(extNetworkId);
}
if (fixedNeutronPortName != null) {
List<Ports> portsList = routerPortsBuilder.getPorts() != null ? new ArrayList<Ports>(routerPortsBuilder.getPorts().values()) : new ArrayList<Ports>();
PortsBuilder fixedNeutronPortBuilder = null;
for (Ports neutronPort : portsList) {
if (neutronPort.getPortName().equals(fixedNeutronPortName)) {
fixedNeutronPortBuilder = new PortsBuilder(neutronPort);
break;
}
}
if (fixedNeutronPortBuilder == null) {
fixedNeutronPortBuilder = new PortsBuilder().withKey(new PortsKey(fixedNeutronPortName)).setPortName(fixedNeutronPortName);
}
if (fixedIpAddress != null) {
Collection<InternalToExternalPortMap> intExtPortMapCollection = fixedNeutronPortBuilder.getInternalToExternalPortMap() != null ? fixedNeutronPortBuilder.getInternalToExternalPortMap().values() : null;
List<InternalToExternalPortMap> intExtPortMapList = new ArrayList<InternalToExternalPortMap>(intExtPortMapCollection != null ? intExtPortMapCollection : Collections.emptyList());
InternalToExternalPortMap intExtPortMap = new InternalToExternalPortMapBuilder().withKey(new InternalToExternalPortMapKey(fixedIpAddress)).setInternalIp(fixedIpAddress).setExternalIp(floatingIpAddress).setExternalId(floatingIpId).build();
intExtPortMapList.add(intExtPortMap);
fixedNeutronPortBuilder.setInternalToExternalPortMap(intExtPortMapList);
}
portsList.add(fixedNeutronPortBuilder.build());
routerPortsBuilder.setPorts(portsList);
}
try (AcquireResult lock = tryRouterLock(routerName)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(routerName);
}
LOG.debug("Creating/Updating routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier, routerPortsBuilder.build());
LOG.debug("FloatingIpInfo DS updated for floating IP {} ", floatingIpAddress);
}
} catch (RuntimeException | ExecutionException | InterruptedException e) {
LOG.error("addToFloatingIpInfo failed for floating IP: {} ", floatingIpAddress, e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder in project bgpcep by opendaylight.
the class FSPortHandler method parsePort.
private static List<Ports> parsePort(final ByteBuf nlri) {
final List<Ports> ports = new ArrayList<>();
boolean end = false;
// we can do this as all fields will be rewritten in the cycle
final PortsBuilder builder = new PortsBuilder();
while (!end) {
final byte b = nlri.readByte();
final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b);
builder.setOp(op);
final short length = AbstractOperandParser.parseLength(b);
builder.setValue(Uint16.valueOf(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))));
end = op.getEndOfList();
ports.add(builder.build());
}
return ports;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder in project netvirt by opendaylight.
the class FloatingIPListener method updateOperationalDS.
static void updateOperationalDS(DataBroker dataBroker, String routerId, String interfaceName, long label, String internalIp, String externalIp) {
LOG.info("updateOperationalDS : Updating operational DS for floating ip config : {} with label {}", internalIp, label);
InstanceIdentifier<Ports> portsId = NatUtil.getPortsIdentifier(routerId, interfaceName);
Optional<Ports> optPorts = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, portsId);
InternalToExternalPortMap intExtPortMap = new InternalToExternalPortMapBuilder().setKey(new InternalToExternalPortMapKey(internalIp)).setInternalIp(internalIp).setExternalIp(externalIp).setLabel(label).build();
if (optPorts.isPresent()) {
LOG.debug("updateOperationalDS : Ports {} entry already present. Updating intExtPortMap for internal ip {}", interfaceName, internalIp);
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, portsId.child(InternalToExternalPortMap.class, new InternalToExternalPortMapKey(internalIp)), intExtPortMap);
} else {
LOG.debug("updateOperationalDS : Adding Ports entry {} along with intExtPortMap {}", interfaceName, internalIp);
List<InternalToExternalPortMap> intExtPortMapList = new ArrayList<>();
intExtPortMapList.add(intExtPortMap);
Ports ports = new PortsBuilder().setKey(new PortsKey(interfaceName)).setPortName(interfaceName).setInternalToExternalPortMap(intExtPortMapList).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, portsId, ports);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method setPortDesc.
private static MultipartReplyPortDescCase setPortDesc(final ByteBuf input) {
MultipartReplyPortDescCaseBuilder caseBuilder = new MultipartReplyPortDescCaseBuilder();
MultipartReplyPortDescBuilder builder = new MultipartReplyPortDescBuilder();
List<Ports> portsList = new ArrayList<>();
while (input.readableBytes() > 0) {
PortsBuilder portsBuilder = new PortsBuilder();
portsBuilder.setPortNo(input.readUnsignedInt());
input.skipBytes(PADDING_IN_PORT_DESC_HEADER_01);
portsBuilder.setHwAddr(ByteBufUtils.readIetfMacAddress(input));
input.skipBytes(PADDING_IN_PORT_DESC_HEADER_02);
portsBuilder.setName(ByteBufUtils.decodeNullTerminatedString(input, EncodeConstants.MAX_PORT_NAME_LENGTH));
portsBuilder.setConfig(createPortConfig(input.readUnsignedInt()));
portsBuilder.setState(createPortState(input.readUnsignedInt()));
portsBuilder.setCurrentFeatures(createPortFeatures(input.readUnsignedInt()));
portsBuilder.setAdvertisedFeatures(createPortFeatures(input.readUnsignedInt()));
portsBuilder.setSupportedFeatures(createPortFeatures(input.readUnsignedInt()));
portsBuilder.setPeerFeatures(createPortFeatures(input.readUnsignedInt()));
portsBuilder.setCurrSpeed(input.readUnsignedInt());
portsBuilder.setMaxSpeed(input.readUnsignedInt());
portsList.add(portsBuilder.build());
}
builder.setPorts(portsList);
caseBuilder.setMultipartReplyPortDesc(builder.build());
return caseBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder in project openflowplugin by opendaylight.
the class PortConvertorTest method testtoPortDescwithAllParameters.
/**
* test of {@link PortConvertor#toPortDesc(FlowCapablePort , short)}.
*/
@Test
public void testtoPortDescwithAllParameters() {
State state = new StateBuilder().setBlocked(false).setLinkDown(false).setLive(false).build();
FlowCapableNodeConnectorBuilder flowCapableNodeConnectorBuilder = new FlowCapableNodeConnectorBuilder();
flowCapableNodeConnectorBuilder.setAdvertisedFeatures(features);
flowCapableNodeConnectorBuilder.setConfiguration(config);
flowCapableNodeConnectorBuilder.setCurrentFeature(features);
flowCapableNodeConnectorBuilder.setCurrentSpeed(null);
flowCapableNodeConnectorBuilder.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
flowCapableNodeConnectorBuilder.setMaximumSpeed(null);
flowCapableNodeConnectorBuilder.setName("foo");
flowCapableNodeConnectorBuilder.setPeerFeatures(features);
flowCapableNodeConnectorBuilder.setPortNumber(new PortNumberUni(42L));
flowCapableNodeConnectorBuilder.setState(state);
flowCapableNodeConnectorBuilder.setSupported(features);
final Ports portsOut = PortConvertor.toPortDesc(flowCapableNodeConnectorBuilder.build(), EncodeConstants.OF13_VERSION_ID);
PortsBuilder portsB = new PortsBuilder();
portsB.setAdvertisedFeatures(portf31);
portsB.setConfig(config31);
portsB.setCurrentFeatures(portf31);
portsB.setCurrSpeed(null);
portsB.setHwAddr(new MacAddress(DEFAULT_MAC_ADDRESS));
portsB.setMaxSpeed(null);
portsB.setName("foo");
portsB.setPeerFeatures(portf31);
portsB.setPortNo(42L);
portsB.setState(new PortState(false, false, false));
portsB.setSupportedFeatures(portf31);
Assert.assertEquals(portsB.build(), portsOut);
}
Aggregations