Search in sources :

Example 41 with Uint64

use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.

the class EvpnDnatFlowProgrammer method onAddFloatingIp.

public void onAddFloatingIp(final Uint64 dpnId, final String routerName, final Uint32 routerId, final String vpnName, final String internalIp, final String externalIp, final Uuid networkId, final String interfaceName, final String floatingIpInterface, final String floatingIpPortMacAddress, final String rd, final String nextHopIp, final TypedReadWriteTransaction<Configuration> confTx) {
    /*
     *  1) Install the flow INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25) (SNAT VM on DPN1 is
     *     responding back to FIP VM on DPN2) {SNAT to DNAT traffic on different Hypervisor}
     *
     *  2) Install the flow L3_FIB_TABLE (table=21)-> PDNAT_TABLE (table=25) (FIP VM1 to FIP VM2
     *    Traffic on Same Hypervisor) {DNAT to DNAT on Same Hypervisor}
     *
     *  3) Install the flow L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
     *    (DC-GW is responding back to FIP VM) {DNAT Reverse traffic})
     *
     */
    Uint32 vpnId = NatUtil.getVpnId(dataBroker, vpnName);
    if (vpnId == NatConstants.INVALID_ID) {
        LOG.error("onAddFloatingIp : Invalid Vpn Id is found for Vpn Name {}", vpnName);
        return;
    }
    Uint32 l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
    if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
        LOG.debug("onAddFloatingIp : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue with installing " + "DNAT flows for FloatingIp {}", vpnName, rd, externalIp);
        l3Vni = natOverVxlanUtil.getInternetVpnVni(vpnName, routerId);
    }
    FloatingIPListener.updateOperationalDS(dataBroker, routerName, interfaceName, NatConstants.DEFAULT_LABEL_VALUE, internalIp, externalIp);
    String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
    // Inform to FIB and BGP
    NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, vpnName, rd, fibExternalIp, nextHopIp, l3Vni, floatingIpInterface, floatingIpPortMacAddress, confTx, RouteOrigin.STATIC, dpnId, networkId);
    /* Install the flow table L3_FIB_TABLE (table=21)-> PDNAT_TABLE (table=25)
         * (SNAT to DNAT reverse traffic: If the DPN has both SNAT and  DNAT configured )
         */
    List<ActionInfo> actionInfoFib = new ArrayList<>();
    actionInfoFib.add(new ActionSetFieldEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
    List<Instruction> instructionsFib = new ArrayList<>();
    instructionsFib.add(new InstructionApplyActions(actionInfoFib).buildInstruction(0));
    instructionsFib.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(1));
    CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setIpAddress(fibExternalIp).setServiceId(l3Vni).setIpAddressSource(CreateFibEntryInput.IpAddressSource.FloatingIP).setInstruction(instructionsFib).build();
    ListenableFuture<RpcResult<CreateFibEntryOutput>> futureVxlan = fibService.createFibEntry(input);
    LOG.debug("onAddFloatingIp : Add Floating Ip {} , found associated to fixed port {}", externalIp, interfaceName);
    if (floatingIpPortMacAddress != null) {
        LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
            vpnManager.addSubnetMacIntoVpnInstance(vpnName, null, floatingIpPortMacAddress, dpnId, tx);
            vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName, Collections.singleton(externalIp), floatingIpPortMacAddress, dpnId, networkId);
        }), LOG, "Error processing floating IP port with MAC address {}", floatingIpPortMacAddress);
    }
    final Uint32 finalL3Vni = l3Vni;
    Futures.addCallback(futureVxlan, new FutureCallback<RpcResult<CreateFibEntryOutput>>() {

        @Override
        public void onFailure(@NonNull Throwable error) {
            LOG.error("onAddFloatingIp : Error {} in custom fib routes install process for Floating " + "IP Prefix {} on DPN {}", error, externalIp, dpnId);
        }

        @Override
        public void onSuccess(@NonNull RpcResult<CreateFibEntryOutput> result) {
            if (result.isSuccessful()) {
                LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, innerConfTx -> {
                    LOG.info("onAddFloatingIp : Successfully installed custom FIB routes for Floating " + "IP Prefix {} on DPN {}", externalIp, dpnId);
                    List<Instruction> instructions = new ArrayList<>();
                    List<ActionInfo> actionsInfos = new ArrayList<>();
                    List<Instruction> customInstructions = new ArrayList<>();
                    customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(0));
                    actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
                    instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
                    /* If more than one floatingIp is available in vpn-to-dpn-list for given dpn id, do not
                            call for
                             * installing INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry with
                             * same tunnel_id
                             * again and again.
                             */
                    if (!NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, true)) {
                        makeTunnelTableEntry(dpnId, finalL3Vni, instructions, innerConfTx);
                    }
                    /* Install the flow L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
                             * (DNAT reverse traffic: If the traffic is Initiated from DC-GW to FIP VM (DNAT forward
                             * traffic))
                             */
                    NatEvpnUtil.makeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress, customInstructions, mdsalManager, innerConfTx);
                }), LOG, "Error installing DNAT flows");
            } else {
                LOG.error("onAddFloatingIp : Error {} in rpc call to create custom Fib entries for Floating " + "IP Prefix {} on DPN {}", result.getErrors(), externalIp, dpnId);
            }
        }
    }, MoreExecutors.directExecutor());
    // Read the FIP vpn-interface details from Configuration l3vpn:vpn-interfaces model and write into Operational DS
    InstanceIdentifier<VpnInterface> vpnIfIdentifier = NatUtil.getVpnInterfaceIdentifier(floatingIpInterface);
    Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
    if (optionalVpnInterface.isPresent()) {
        LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
            for (VpnInstanceNames vpnInstance : optionalVpnInterface.get().nonnullVpnInstanceNames().values()) {
                if (!vpnName.equals(vpnInstance.getVpnName())) {
                    continue;
                }
                VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get());
                Adjacencies adjs = vpnIfBuilder.augmentation(Adjacencies.class);
                VpnInterfaceOpDataEntryBuilder vpnIfOpDataEntryBuilder = new VpnInterfaceOpDataEntryBuilder();
                vpnIfOpDataEntryBuilder.withKey(new VpnInterfaceOpDataEntryKey(interfaceName, vpnName));
                Map<AdjacencyKey, Adjacency> keyAdjacencyMap = adjs != null && adjs.getAdjacency() != null ? adjs.nonnullAdjacency() : new HashMap<>();
                List<Adjacency> adjacencyListToImport = new ArrayList<>();
                for (Adjacency adj : keyAdjacencyMap.values()) {
                    Subnetmap sn = VpnHelper.getSubnetmapFromItsUuid(dataBroker, adj.getSubnetId());
                    if (!VpnHelper.isSubnetPartOfVpn(sn, vpnName)) {
                        continue;
                    }
                    adjacencyListToImport.add(adj);
                }
                AdjacenciesOp adjacenciesOp = new AdjacenciesOpBuilder().setAdjacency(adjacencyListToImport).build();
                vpnIfOpDataEntryBuilder.addAugmentation(adjacenciesOp);
                LOG.debug("onAddFloatingIp : Add vpnInterface {} to Operational l3vpn:vpn-interfaces-op-data ", floatingIpInterface);
                InstanceIdentifier<VpnInterfaceOpDataEntry> vpnIfIdentifierOpDataEntry = NatUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
                tx.mergeParentStructurePut(vpnIfIdentifierOpDataEntry, vpnIfOpDataEntryBuilder.build());
                break;
            }
        }), LOG, "onAddFloatingIp : Could not write Interface {}, vpnName {}", interfaceName, vpnName);
    } else {
        LOG.debug("onAddFloatingIp : No vpnInterface {} found in Configuration l3vpn:vpn-interfaces ", floatingIpInterface);
    }
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) IFibManager(org.opendaylight.netvirt.fibmanager.api.IFibManager) VpnInterfaceOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryBuilder) FibRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.FibRpcService) LoggerFactory(org.slf4j.LoggerFactory) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Map(java.util.Map) IBgpManager(org.opendaylight.netvirt.bgpmanager.api.IBgpManager) BigInteger(java.math.BigInteger) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) AdjacenciesOpBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOpBuilder) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) CreateFibEntryOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryOutput) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey) Configuration(org.opendaylight.mdsal.binding.util.Datastore.Configuration) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) RemoveFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInput) VpnHelper(org.opendaylight.netvirt.vpnmanager.api.VpnHelper) List(java.util.List) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) TypedWriteTransaction(org.opendaylight.mdsal.binding.util.TypedWriteTransaction) Optional(java.util.Optional) CreateFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) NonNull(org.eclipse.jdt.annotation.NonNull) InstructionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) Uint64(org.opendaylight.yangtools.yang.common.Uint64) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CreateFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) HashMap(java.util.HashMap) VpnInterfaceOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryKey) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) MatchTunnelId(org.opendaylight.genius.mdsalutil.matches.MatchTunnelId) RemoveFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInputBuilder) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) IVpnManager(org.opendaylight.netvirt.vpnmanager.api.IVpnManager) VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceBuilder) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) RemoveFibEntryOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryOutput) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) Collections(java.util.Collections) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) List(java.util.List) ArrayList(java.util.ArrayList) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) Uint32(org.opendaylight.yangtools.yang.common.Uint32) VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceBuilder) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) CreateFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInputBuilder) CreateFibEntryOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) CreateFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies) VpnInterfaceOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryBuilder) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames) VpnInterfaceOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryKey) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) AdjacenciesOpBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOpBuilder) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Map(java.util.Map) HashMap(java.util.HashMap)

Example 42 with Uint64

use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.

the class Ipv6ForwardingService method removeCentralizedRouter.

@Override
public boolean removeCentralizedRouter(TypedReadWriteTransaction<Configuration> confTx, Routers routers, Uint64 primarySwitchId, Uint64 dpnId) throws ExecutionException, InterruptedException {
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routers.getRouterName());
    Uint64 routerMetadata = MetaDataUtil.getVpnIdMetadata(routerId.longValue());
    if (!dpnId.equals(primarySwitchId)) {
        LOG.info("handleSnat (non-NAPTSwitch) : {} flows on switch {} for router {}", "Removing", dpnId, routers.getRouterName());
        // Program default flow from FIB_TABLE(21) to PSNAT_TABLE(26) (egress direction)
        addIpv6DefaultFibRoute(confTx, dpnId, routerId, routerMetadata);
        // Currently we are only programming flows when ext-net has an IPv6Subnet
        if (routerHasIpv6ExtSubnet(routers)) {
            // Program flows on non-NAPTSwitch to send N/S packets to the NAPTSwitch
            addIpv6PsNatMissEntryNonNaptSwitch(confTx, dpnId, routerId, routers.getRouterName(), primarySwitchId);
        }
    } else {
        LOG.info("handleSnat (NAPTSwitch) : {} flows on switch {} for router {}", "Removing", dpnId, routers.getRouterName());
        // Program default flow from FIB_TABLE(21) to PSNAT_TABLE(26) (egress direction)
        removeIpv6DefaultFibRoute(confTx, dpnId, routerId);
        // Program flows from PSNAT_TABLE(26) to OUTBOUND_NAPT_TABLE(46) (egress direction)
        removeIpv6SnatMissEntryForNaptSwitch(confTx, dpnId, routerId);
        // Program flows in INTERNAL_TUNNEL_TABLE(36) for packets coming from non-NAPTSwitch (egress direction)
        removeIpv6TerminatingServiceTblEntry(confTx, dpnId, routerId);
        // Program flows from NAPT_PFIB_TABLE(47) to FIB_TABLE(21) (ingress direction)
        removeIpv6NaptPfibInboundFlow(confTx, dpnId, routerId);
        // Now installing flows that use SubnetInfo
        ipv6SubnetFlowProgrammer.removeSubnetSpecificFlows(confTx, dpnId, routerId, routers);
    }
    return true;
}
Also used : Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 43 with Uint64

use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.

the class NaptEventHandler method prepareAndSendPacketOut.

private void prepareAndSendPacketOut(NAPTEntryEvent naptEntryEvent, Uint32 routerId, String sourceIPPortKey) {
    // Send Packetout - tcp or udp packets which got punted to controller.
    Uint64 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 * Byte.SIZE);
        } catch (PacketException e) {
            NaptPacketInHandler.removeIncomingPacketMap(sourceIPPortKey);
            LOG.error("prepareAndSendPacketOut : Failed to decode Packet", e);
            return;
        }
    }
    long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
    LOG.debug("prepareAndSendPacketOut : portTag from incoming packet is {}", portTag);
    List<ActionInfo> actionInfos = new ArrayList<>();
    String interfaceName = getInterfaceNameFromTag(portTag);
    Uint64 dpnID = null;
    int portNum = -1;
    if (interfaceName != null) {
        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) {
            NaptPacketInHandler.removeIncomingPacketMap(sourceIPPortKey);
            LOG.error("prepareAndSendPacketOut : Unable to read interface {} from config DataStore", interfaceName);
            return;
        }
        IfL2vlan ifL2vlan = iface.augmentation(IfL2vlan.class);
        if (ifL2vlan != null && ifL2vlan.getVlanId() != null) {
            vlanId = ifL2vlan.getVlanId().getValue() == null ? 0 : ifL2vlan.getVlanId().getValue().toJava();
        }
        InterfaceInfo infInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(interfaceName);
        if (infInfo == null) {
            LOG.error("prepareAndSendPacketOut : error in getting interfaceInfo from Operation DS");
            return;
        }
        dpnID = infInfo.getDpId();
        portNum = infInfo.getPortNo();
        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");
        }
    } else {
        // This case will be hit for packets send from non-napt switch.
        LOG.info("prepareAndSendPacketOut : interfaceName is not available.Retrieve from packet received");
        NodeConnectorId nodeId = naptEntryEvent.getPacketReceived().getMatch().getInPort();
        portNum = Integer.parseInt(nodeId.getValue());
        LOG.debug("prepareAndSendPacketOut : in_port portNum : {}", portNum);
        // List<PathArgument> dpnNodes = naptEntryEvent.getPacketReceived().getIngress().getValue().getPath();
        Iterable<PathArgument> outArgs = naptEntryEvent.getPacketReceived().getIngress().getValue().getPathArguments();
        PathArgument pathArgument = Iterables.get(outArgs, 2);
        LOG.debug("prepareAndSendPacketOut : pathArgument : {}", pathArgument);
        InstanceIdentifier.IdentifiableItem<?, ?> item = Arguments.checkInstanceOf(pathArgument, InstanceIdentifier.IdentifiableItem.class);
        NodeConnectorKey key = Arguments.checkInstanceOf(item.getKey(), NodeConnectorKey.class);
        LOG.info("prepareAndSendPacketOut : NodeConnectorKey key : {}", key.getId().getValue());
        String dpnKey = key.getId().getValue();
        if (dpnKey.contains(NatConstants.COLON_SEPARATOR)) {
            dpnID = Uint64.valueOf(dpnKey.split(NatConstants.COLON_SEPARATOR)[1]).intern();
        }
    }
    byte[] pktOut = buildNaptPacketOut(ethPkt);
    if (pktOut != null) {
        String routerName = NatUtil.getRouterName(dataBroker, routerId);
        Uint64 tunId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, natOverVxlanUtil, elanManager, idManager, routerId, routerName);
        LOG.info("sendNaptPacketOut for ({}:{}) on dpnId {} portNum {} tunId {}", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), dpnID, portNum, tunId);
        sendNaptPacketOut(pktOut, dpnID, portNum, actionInfos, tunId);
    } else {
        LOG.warn("prepareAndSendPacketOut : Unable to send Packet Out");
    }
}
Also used : NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) ArrayList(java.util.ArrayList) ActionSetFieldVlanVid(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldVlanVid) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan) ActionPushVlan(org.opendaylight.genius.mdsalutil.actions.ActionPushVlan) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo) PathArgument(org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 44 with Uint64

use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.

the class ExternalRoutersListener method buildTsFlowEntity.

private FlowEntity buildTsFlowEntity(Uint64 dpId, String routerName, Uint32 routerId) {
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    Uint64 tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, natOverVxlanUtil, elanManager, idManager, routerId, routerName);
    matches.add(new MatchTunnelId(tunnelId));
    String flowRef = getFlowRefTs(dpId, NwConstants.INTERNAL_TUNNEL_TABLE, Uint32.valueOf(tunnelId.longValue()));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionWriteMetadata(MetaDataUtil.getVpnIdMetadata(routerId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
    instructions.add(new InstructionGotoTable(NwConstants.OUTBOUND_NAPT_TABLE));
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.INTERNAL_TUNNEL_TABLE, flowRef, NatConstants.DEFAULT_TS_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_TS_TABLE, matches, instructions);
    return flowEntity;
}
Also used : MatchTunnelId(org.opendaylight.genius.mdsalutil.matches.MatchTunnelId) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ArrayList(java.util.ArrayList) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) Uint64(org.opendaylight.yangtools.yang.common.Uint64) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 45 with Uint64

use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.

the class ExternalRoutersListener method removeFlowsFromNonActiveSwitches.

public void removeFlowsFromNonActiveSwitches(Uint32 routerId, String routerName, Uint64 naptSwitchDpnId, TypedReadWriteTransaction<Configuration> removeFlowInvTx) throws ExecutionException, InterruptedException {
    LOG.debug("removeFlowsFromNonActiveSwitches : Remove NAPT related flows from non active switches");
    // Remove the flows from the other switches which points to the primary and secondary switches
    // for the flows related the router ID.
    List<Uint64> allSwitchList = naptSwitchSelector.getDpnsForVpn(routerName);
    if (allSwitchList.isEmpty()) {
        LOG.error("removeFlowsFromNonActiveSwitches : Unable to get the swithces for the router {}", routerName);
        return;
    }
    for (Uint64 dpnId : allSwitchList) {
        if (!naptSwitchDpnId.equals(dpnId)) {
            LOG.info("removeFlowsFromNonActiveSwitches : Handle Ordinary switch");
            // Remove the PSNAT entry which forwards the packet to Terminating Service table
            String preSnatFlowRef = getFlowRefSnat(dpnId, NwConstants.PSNAT_TABLE, String.valueOf(routerName));
            FlowEntity preSnatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.PSNAT_TABLE, preSnatFlowRef);
            LOG.info("removeFlowsFromNonActiveSwitches : Remove the flow in the {} for the non active switch " + "with the DPN ID {} and router ID {}", NwConstants.PSNAT_TABLE, dpnId, routerId);
            mdsalManager.removeFlow(removeFlowInvTx, preSnatFlowEntity);
            // Remove the group entry which forwards the traffic to the out port (VXLAN tunnel).
            Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(routerName));
            if (groupId != NatConstants.INVALID_ID) {
                LOG.info("removeFlowsFromNonActiveSwitches : Remove the group {} for the non active switch with " + "the DPN ID {} and router ID {}", groupId, dpnId, routerId);
                mdsalManager.removeGroup(removeFlowInvTx, dpnId, groupId.longValue());
            } else {
                LOG.error("removeFlowsFromNonActiveSwitches: Unable to obtained groupID for router:{}", routerName);
            }
        }
    }
}
Also used : Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Aggregations

Uint64 (org.opendaylight.yangtools.yang.common.Uint64)306 ArrayList (java.util.ArrayList)119 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)104 ExecutionException (java.util.concurrent.ExecutionException)86 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)66 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)65 ManagedNewTransactionRunner (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner)64 ManagedNewTransactionRunnerImpl (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl)64 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)64 Logger (org.slf4j.Logger)63 LoggerFactory (org.slf4j.LoggerFactory)63 Inject (javax.inject.Inject)59 Singleton (javax.inject.Singleton)59 List (java.util.List)58 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)58 CONFIGURATION (org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION)54 Optional (java.util.Optional)49 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)48 Collections (java.util.Collections)48 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)48