Search in sources :

Example 1 with VlanId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId in project netvirt by opendaylight.

the class HwvtepTerminationPointListener method getVlanBindings.

private List<VlanBindings> getVlanBindings(List<L2gatewayConnection> l2GwConns, NodeId hwvtepNodeId, String psName, String newPortId) {
    List<VlanBindings> vlanBindings = new ArrayList<>();
    for (L2gatewayConnection l2GwConn : l2GwConns) {
        L2gateway l2Gateway = L2GatewayConnectionUtils.getNeutronL2gateway(broker, l2GwConn.getL2gatewayId());
        if (l2Gateway == null) {
            LOG.error("L2Gateway with id {} is not present", l2GwConn.getL2gatewayId().getValue());
        } else {
            String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(l2GwConn.getNetworkId().getValue());
            List<Devices> l2Devices = l2Gateway.getDevices();
            for (Devices l2Device : l2Devices) {
                String l2DeviceName = l2Device.getDeviceName();
                if (l2DeviceName != null && l2DeviceName.equals(psName)) {
                    for (Interfaces deviceInterface : l2Device.getInterfaces()) {
                        if (deviceInterface.getInterfaceName().equals(newPortId)) {
                            if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
                                for (Integer vlanId : deviceInterface.getSegmentationIds()) {
                                    vlanBindings.add(HwvtepSouthboundUtils.createVlanBinding(hwvtepNodeId, vlanId, logicalSwitchName));
                                }
                            } else {
                                // Use defaultVlanId (specified in L2GatewayConnection) if Vlan
                                // ID not specified at interface level.
                                Integer segmentationId = l2GwConn.getSegmentId();
                                int defaultVlanId = segmentationId != null ? segmentationId : 0;
                                vlanBindings.add(HwvtepSouthboundUtils.createVlanBinding(hwvtepNodeId, defaultVlanId, logicalSwitchName));
                            }
                        }
                    }
                }
            }
        }
    }
    return vlanBindings;
}
Also used : Interfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces) ArrayList(java.util.ArrayList) VlanBindings(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings) L2gateway(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway) Devices(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection)

Example 2 with VlanId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId 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 3 with VlanId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId in project netvirt by opendaylight.

the class ElanL2GatewayUtils method deleteVlanBindingsFromL2GatewayDevice.

/**
 * Delete vlan bindings from l2 gateway device.
 *
 * @param nodeId
 *            the node id
 * @param hwVtepDevice
 *            the hw vtep device
 * @param defaultVlanId
 *            the default vlan id
 * @return the listenable future
 */
public ListenableFuture<Void> deleteVlanBindingsFromL2GatewayDevice(NodeId nodeId, Devices hwVtepDevice, Integer defaultVlanId) {
    if (hwVtepDevice == null || hwVtepDevice.getInterfaces() == null || hwVtepDevice.getInterfaces().isEmpty()) {
        String errMsg = "HwVtepDevice is null or interfaces are empty.";
        LOG.error(errMsg);
        return Futures.immediateFailedFuture(new RuntimeException(errMsg));
    }
    NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, hwVtepDevice.getDeviceName());
    return txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
        for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
            String phyPortName = deviceInterface.getInterfaceName();
            if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
                for (Integer vlanId : deviceInterface.getSegmentationIds()) {
                    HwvtepUtils.deleteVlanBinding(tx, physicalSwitchNodeId, phyPortName, vlanId);
                }
            } else {
                // Use defaultVlanId (specified in L2GatewayConnection) if Vlan
                // ID not specified at interface level.
                HwvtepUtils.deleteVlanBinding(tx, physicalSwitchNodeId, phyPortName, defaultVlanId);
            }
        }
        LOG.info("Deleted Hwvtep VlanBindings from config DS. NodeID: {}, hwVtepDevice: {}, defaultVlanId: {} ", nodeId.getValue(), hwVtepDevice, defaultVlanId);
    });
}
Also used : BigInteger(java.math.BigInteger) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)

Example 4 with VlanId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId in project netvirt by opendaylight.

the class ElanItmUtils method getExternalTunnelItmEgressAction.

/**
 * Builds the list of actions to be taken when sending the packet over an
 * external VxLan tunnel interface, such as stamping the VNI on the VxLAN
 * header, setting the vlanId if it proceeds and output the packet over the
 * right port.
 *
 * @param srcDpnId
 *            Dpn where the tunnelInterface is located
 * @param torNode
 *            NodeId of the ExternalDevice where the packet must be sent to.
 * @param vni
 *            Vni to be stamped on the VxLAN Header.
 * @return the external itm egress action
 */
public List<Action> getExternalTunnelItmEgressAction(BigInteger srcDpnId, NodeId torNode, long vni) {
    List<Action> result = Collections.emptyList();
    GetExternalTunnelInterfaceNameInput input = new GetExternalTunnelInterfaceNameInputBuilder().setDestinationNode(torNode.getValue()).setSourceNode(srcDpnId.toString()).setTunnelType(TunnelTypeVxlan.class).build();
    Future<RpcResult<GetExternalTunnelInterfaceNameOutput>> output = itmRpcService.getExternalTunnelInterfaceName(input);
    try {
        if (output.get().isSuccessful()) {
            GetExternalTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
            String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
            LOG.debug("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
            result = buildTunnelItmEgressActions(tunnelIfaceName, vni);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
    }
    return result;
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) GetExternalTunnelInterfaceNameInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetExternalTunnelInterfaceNameInput) GetExternalTunnelInterfaceNameOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetExternalTunnelInterfaceNameOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TunnelTypeVxlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan) ExecutionException(java.util.concurrent.ExecutionException) GetExternalTunnelInterfaceNameInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetExternalTunnelInterfaceNameInputBuilder)

Example 5 with VlanId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId in project netvirt by opendaylight.

the class ElanItmUtils method getInternalTunnelItmEgressAction.

/**
 * Builds the list of actions to be taken when sending the packet over an internal VxLAN tunnel interface, such
 * as setting the serviceTag/segmentationID on the VNI field of the VxLAN header, setting the vlanId if it proceeds
 * and output the packet over the right port.
 *
 * @param sourceDpnId
 *            Dpn where the tunnelInterface is located
 * @param destinationDpnId
 *            Dpn where the packet must be sent to. It is used here in order
 *            to select the right tunnel interface.
 * @param tunnelKey
 *            Tunnel key to be sent on the VxLAN header.
 * @return the internal itm egress action
 */
public List<Action> getInternalTunnelItmEgressAction(BigInteger sourceDpnId, BigInteger destinationDpnId, long tunnelKey) {
    List<Action> result = Collections.emptyList();
    LOG.trace("In getInternalItmEgressAction Action source {}, destination {}, serviceTag/Vni {}", sourceDpnId, destinationDpnId, tunnelKey);
    Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
    GetTunnelInterfaceNameInput input = new GetTunnelInterfaceNameInputBuilder().setDestinationDpid(destinationDpnId).setSourceDpid(sourceDpnId).setTunnelType(tunType).build();
    Future<RpcResult<GetTunnelInterfaceNameOutput>> output = itmRpcService.getTunnelInterfaceName(input);
    try {
        if (output.get().isSuccessful()) {
            GetTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
            String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
            LOG.info("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
            result = buildTunnelItmEgressActions(tunnelIfaceName, tunnelKey);
        } else {
            LOG.trace("Tunnel interface doesn't exist between srcDpId {} dstDpId {}", sourceDpnId, destinationDpnId);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
    }
    return result;
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) GetTunnelInterfaceNameInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetTunnelInterfaceNameOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameOutput) TunnelTypeVxlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan) GetTunnelInterfaceNameInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameInputBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ArrayList (java.util.ArrayList)27 VlanId (org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId)26 BigInteger (java.math.BigInteger)14 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)12 IfL2vlan (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan)12 List (java.util.List)11 Test (org.junit.Test)11 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)10 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)10 VlanMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder)10 VlanIdBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder)10 SetVlanIdActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder)9 SubnetsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey)9 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)8 SetVlanIdActionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder)6 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)6 ParentRefs (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs)6 TransportZoneKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)6 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)6 VtepsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsKey)6