Search in sources :

Example 1 with IfL2vlan

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan in project netvirt by opendaylight.

the class NaptEventHandler method prepareAndSendPacketOut.

private void prepareAndSendPacketOut(NAPTEntryEvent naptEntryEvent, Long routerId) {
    // Send Packetout - tcp or udp packets which got punted to controller.
    BigInteger metadata = naptEntryEvent.getPacketReceived().getMatch().getMetadata().getMetadata();
    byte[] inPayload = naptEntryEvent.getPacketReceived().getPayload();
    Ethernet ethPkt = new Ethernet();
    if (inPayload != null) {
        try {
            ethPkt.deserialize(inPayload, 0, inPayload.length * NetUtils.NUM_BITS_IN_A_BYTE);
        } catch (PacketException e) {
            LOG.error("prepareAndSendPacketOut : Failed to decode Packet", e);
            return;
        }
    }
    long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
    LOG.debug("prepareAndSendPacketOut : portTag from incoming packet is {}", portTag);
    String interfaceName = getInterfaceNameFromTag(portTag);
    LOG.debug("prepareAndSendPacketOut : interfaceName fetched from portTag is {}", interfaceName);
    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = null;
    int vlanId = 0;
    iface = interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
    if (iface == null) {
        LOG.error("prepareAndSendPacketOut : Unable to read interface {} from config DataStore", interfaceName);
        return;
    }
    List<ActionInfo> actionInfos = new ArrayList<>();
    IfL2vlan ifL2vlan = iface.getAugmentation(IfL2vlan.class);
    if (ifL2vlan != null && ifL2vlan.getVlanId() != null) {
        vlanId = ifL2vlan.getVlanId().getValue() == null ? 0 : ifL2vlan.getVlanId().getValue();
    }
    InterfaceInfo infInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(interfaceName);
    if (infInfo == null) {
        LOG.error("prepareAndSendPacketOut : error in getting interfaceInfo from Operation DS");
        return;
    }
    byte[] pktOut = buildNaptPacketOut(ethPkt);
    if (ethPkt.getEtherType() != (short) NwConstants.ETHTYPE_802_1Q) {
        // VLAN Access port
        LOG.debug("prepareAndSendPacketOut : vlanId is {}", vlanId);
        if (vlanId != 0) {
            // Push vlan
            actionInfos.add(new ActionPushVlan(0));
            actionInfos.add(new ActionSetFieldVlanVid(1, vlanId));
        } else {
            LOG.debug("prepareAndSendPacketOut : No vlanId {}, may be untagged", vlanId);
        }
    } else {
        // VLAN Trunk Port
        LOG.debug("prepareAndSendPacketOut : This is VLAN Trunk port case - need not do VLAN tagging again");
    }
    if (pktOut != null) {
        String routerName = NatUtil.getRouterName(dataBroker, routerId);
        long tunId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId, routerName);
        sendNaptPacketOut(pktOut, infInfo, actionInfos, tunId);
    } else {
        LOG.warn("prepareAndSendPacketOut : Unable to send Packet Out");
    }
}
Also used : ArrayList(java.util.ArrayList) ActionSetFieldVlanVid(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldVlanVid) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionPushVlan(org.opendaylight.genius.mdsalutil.actions.ActionPushVlan) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) BigInteger(java.math.BigInteger) InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan)

Example 2 with IfL2vlan

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan in project netvirt by opendaylight.

the class ExpectedObjects method newInterfaceConfig.

public static Interface newInterfaceConfig(final String interfaceName, final String parentName) {
    InterfaceBuilder _interfaceBuilder = new InterfaceBuilder();
    final Procedure1<InterfaceBuilder> _function = (InterfaceBuilder it) -> {
        it.setDescription(interfaceName);
        it.setName(interfaceName);
        it.setType(L2vlan.class);
        ParentRefsBuilder _parentRefsBuilder = new ParentRefsBuilder();
        final Procedure1<ParentRefsBuilder> _function_1 = (ParentRefsBuilder it_1) -> {
            it_1.setParentInterface(parentName);
        };
        ParentRefs _doubleGreaterThan = XtendBuilderExtensions.<ParentRefs, ParentRefsBuilder>operator_doubleGreaterThan(_parentRefsBuilder, _function_1);
        it.addAugmentation(ParentRefs.class, _doubleGreaterThan);
        IfL2vlanBuilder _ifL2vlanBuilder = new IfL2vlanBuilder();
        final Procedure1<IfL2vlanBuilder> _function_2 = (IfL2vlanBuilder it_1) -> {
            it_1.setL2vlanMode(IfL2vlan.L2vlanMode.Trunk);
            VlanId _vlanId = new VlanId(Integer.valueOf(0));
            it_1.setVlanId(_vlanId);
        };
        IfL2vlan _doubleGreaterThan_1 = XtendBuilderExtensions.<IfL2vlan, IfL2vlanBuilder>operator_doubleGreaterThan(_ifL2vlanBuilder, _function_2);
        it.addAugmentation(IfL2vlan.class, _doubleGreaterThan_1);
    };
    return XtendBuilderExtensions.<Interface, InterfaceBuilder>operator_doubleGreaterThan(_interfaceBuilder, _function);
}
Also used : IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan) L2vlan(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan) ParentRefs(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) InterfaceBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder) IfL2vlanBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlanBuilder) VlanId(org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface) ParentRefsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefsBuilder) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan)

Example 3 with IfL2vlan

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan in project netvirt by opendaylight.

the class DhcpInterfaceConfigListener method remove.

@Override
protected void remove(InstanceIdentifier<Interface> identifier, Interface del) {
    jobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(del.getName()), () -> {
        IfTunnel tunnelInterface = del.getAugmentation(IfTunnel.class);
        IfL2vlan vlanInterface = del.getAugmentation(IfL2vlan.class);
        String interfaceName = del.getName();
        if (tunnelInterface != null && !tunnelInterface.isInternal()) {
            IpAddress tunnelIp = tunnelInterface.getTunnelDestination();
            ParentRefs interfce = del.getAugmentation(ParentRefs.class);
            if (interfce != null) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Calling handleTunnelStateDown for tunnelIp {} and interface {}", tunnelIp, interfaceName);
                }
                return dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp, interfce.getDatapathNodeIdentifier());
            }
        }
        if (vlanInterface != null) {
            return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> DhcpServiceUtils.unbindDhcpService(interfaceName, tx)));
        }
        return Collections.emptyList();
    }, DhcpMConstants.RETRY_COUNT);
}
Also used : Logger(org.slf4j.Logger) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) DhcpMConstants(org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) LoggerFactory(org.slf4j.LoggerFactory) AsyncDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Interfaces(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) ParentRefs(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) Collections(java.util.Collections) ParentRefs(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan)

Example 4 with IfL2vlan

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan in project netvirt by opendaylight.

the class DhcpInterfaceConfigListener method add.

@Override
protected void add(InstanceIdentifier<Interface> identifier, Interface add) {
    jobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(add.getName()), () -> {
        String interfaceName = add.getName();
        IfL2vlan vlanInterface = add.getAugmentation(IfL2vlan.class);
        if (vlanInterface == null) {
            return Collections.emptyList();
        }
        Port port = dhcpManager.getNeutronPort(interfaceName);
        Subnet subnet = dhcpManager.getNeutronSubnet(port);
        if (null != subnet && subnet.isEnableDhcp()) {
            return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
                LOG.debug("Binding DHCP service for interface {}", interfaceName);
                DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, tx);
            }));
        }
        return Collections.emptyList();
    }, DhcpMConstants.RETRY_COUNT);
}
Also used : Logger(org.slf4j.Logger) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) DhcpMConstants(org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) LoggerFactory(org.slf4j.LoggerFactory) AsyncDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Interfaces(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) ParentRefs(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) Collections(java.util.Collections) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan)

Example 5 with IfL2vlan

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan in project netvirt by opendaylight.

the class NeutronTrunkChangeListener method deleteSubPortInterface.

private void deleteSubPortInterface(SubPorts subPort) {
    String portName = subPort.getPortId().getValue();
    InstanceIdentifier<Interface> interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(subPort.getPortId().getValue());
    jobCoordinator.enqueueJob("PORT- " + portName, () -> {
        Interface iface = ifMgr.getInterfaceInfoFromConfigDataStore(portName);
        List<ListenableFuture<Void>> futures = new ArrayList<>();
        if (iface == null) {
            LOG.warn("Interface not present for SubPort {}", subPort);
            return futures;
        }
        /*
             * We'll reset interface back to way it was? Can IFM handle parentRef delete?
             */
        InterfaceBuilder interfaceBuilder = new InterfaceBuilder(iface);
        // Reset augmentations
        interfaceBuilder.removeAugmentation(IfL2vlan.class).removeAugmentation(ParentRefs.class).removeAugmentation(SplitHorizon.class);
        IfL2vlan ifL2vlan = new IfL2vlanBuilder().setL2vlanMode(IfL2vlan.L2vlanMode.Trunk).build();
        interfaceBuilder.addAugmentation(IfL2vlan.class, ifL2vlan);
        iface = interfaceBuilder.build();
        /*
             * There is no means to do an update to remove elements from a node.
             * Our solution is to get existing iface, remove parentRef and VlanId,
             * and do a put to replace existing entry. This works out better as put
             * has better performance than merge.
             * Only drawback is any in-flight changes might be lost, but that is a corner case
             * and this being subport delete path, don't expect any significant changes to
             * corresponding Neutron Port. Deletion of NeutronPort should follow soon enough.
             */
        WriteTransaction txn = dataBroker.newWriteOnlyTransaction();
        txn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, iface);
        LOG.trace("Resetting trunk member interface {}", iface);
        futures.add(txn.submit());
        return futures;
    });
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ParentRefs(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InterfaceBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder) IfL2vlanBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlanBuilder) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan)

Aggregations

IfL2vlan (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan)23 ParentRefs (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs)11 ArrayList (java.util.ArrayList)9 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface)9 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 Collections (java.util.Collections)5 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)5 IfTunnel (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 BigInteger (java.math.BigInteger)4 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)4 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)4 ManagedNewTransactionRunnerImpl (org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl)4 VlanId (org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId)4 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)4 List (java.util.List)3 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)3 InterfaceManagerCommonUtils (org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils)3 InterfaceBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder)3