Search in sources :

Example 6 with PortsBuilder

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);
    }
}
Also used : InternalToExternalPortMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapKey) RouterPortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) ArrayList(java.util.ArrayList) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult) InternalToExternalPortMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapBuilder) RouterPortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsBuilder) RouterPortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsBuilder) PortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsBuilder) ExecutionException(java.util.concurrent.ExecutionException) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) PortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey) RouterPortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey)

Example 7 with PortsBuilder

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;
}
Also used : NumericOperand(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.NumericOperand) ArrayList(java.util.ArrayList) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports) PortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder)

Example 8 with PortsBuilder

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);
    }
}
Also used : InternalToExternalPortMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapKey) ArrayList(java.util.ArrayList) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) InternalToExternalPortMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapBuilder) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) PortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsBuilder) PortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey)

Example 9 with PortsBuilder

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();
}
Also used : MultipartReplyPortDescBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.MultipartReplyPortDescBuilder) MultipartReplyPortDescCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDescCaseBuilder) ArrayList(java.util.ArrayList) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.Ports) PortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.PortsBuilder)

Example 10 with PortsBuilder

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);
}
Also used : FlowCapableNodeConnectorBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder) PortState(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState) State(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State) PortState(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState) PortNumberUni(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni) StateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.StateBuilder) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.Ports) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) PortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.PortsBuilder) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)11 Test (org.junit.Test)5 PortsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.PortsBuilder)5 PortsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder)5 NumericOperand (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.NumericOperand)4 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)3 Ports (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports)3 PortsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsBuilder)3 PortsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey)3 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)3 InternalToExternalPortMapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapBuilder)3 InternalToExternalPortMapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapKey)3 PortState (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState)3 Ports (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.Ports)3 DestinationPortsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPortsBuilder)3 Ports (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports)3 SourcePortsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePortsBuilder)3 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)2 PortNumberUni (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni)2 PortConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig)2