Search in sources :

Example 86 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project netvirt by opendaylight.

the class BgpAlarms method processNeighborStatusMap.

private void processNeighborStatusMap(Map<String, String> nbrStatusMap, List<Neighbors> nbrs) {
    if (nbrs == null || nbrs.isEmpty()) {
        LOG.trace("No BGP neighbors configured.");
        return;
    }
    for (Neighbors nbr : nbrs) {
        boolean alarmToRaise = true;
        if (nbrStatusMap != null && nbrStatusMap.containsKey(nbr.getAddress().getValue())) {
            String nbrshipStatus = nbrStatusMap.get(nbr.getAddress().getValue());
            LOG.trace("nbr {} status {}", nbr.getAddress().getValue(), nbrshipStatus);
            try {
                Integer.parseInt(nbrshipStatus);
                alarmToRaise = false;
            } catch (NumberFormatException e) {
                LOG.trace("Exception thrown in parsing the integers. {}", e);
            }
            final BgpAlarmStatus alarmStatus = neighborsRaisedAlarmStatusMap.get(nbr.getAddress().getValue());
            if (alarmToRaise) {
                if (alarmStatus == null || alarmStatus != BgpAlarmStatus.RAISED) {
                    LOG.trace("alarm raised for {}.", nbr.getAddress().getValue());
                    raiseBgpNbrDownAlarm(nbr.getAddress().getValue());
                } else {
                    LOG.trace("alarm raised already for {}", nbr.getAddress().getValue());
                }
            } else {
                if (alarmStatus == null || alarmStatus != BgpAlarmStatus.CLEARED) {
                    clearBgpNbrDownAlarm(nbr.getAddress().getValue());
                    LOG.trace("alarm cleared for {}", nbr.getAddress().getValue());
                } else {
                    LOG.trace("alarm cleared already for {}", nbr.getAddress().getValue());
                }
            }
        }
    }
}
Also used : Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors)

Example 87 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project netvirt by opendaylight.

the class NatTunnelInterfaceStateListener method hndlTepAddForSnatInEachRtr.

private void hndlTepAddForSnatInEachRtr(RoutersList router, long routerId, final BigInteger srcDpnId, String tunnelType, String srcTepIp, String destTepIp, String tunnelName, String nextHopIp, ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
    /*SNAT : Remove the old routes to the external IP having the old TEP IP as the next hop IP
                 Advertise to the BGP about the new route to the external IP having the new TEP IP
                  added as the next hop IP
         */
    String routerName = router.getRouter();
    // Check if this is externalRouter else ignore
    InstanceIdentifier<Routers> extRoutersId = NatUtil.buildRouterIdentifier(routerName);
    Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, extRoutersId);
    if (!routerData.isPresent()) {
        LOG.warn("hndlTepAddForSnatInEachRtr : SNAT->Ignoring TEP add for router {} since its not External Router", routerName);
        return;
    }
    BigInteger naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
    if (naptId == null || naptId.equals(BigInteger.ZERO)) {
        LOG.warn("hndlTepAddForSnatInEachRtr : SNAT -> Ignoring TEP add for the DPN {} having the router {} since" + " the router is not part of the NAT service  - the TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and" + "TUNNEL NAME {} ", srcDpnId, routerName, tunnelType, srcTepIp, destTepIp, tunnelName);
        return;
    }
    if (natMode == NatMode.Conntrack) {
        natServiceManager.notify(routerData.get(), naptId, srcDpnId, SnatServiceManager.Action.SNAT_ROUTER_ENBL);
    } else {
        Uuid bgpVpnUuId = NatUtil.getVpnForRouter(dataBroker, routerName);
        // Check if the DPN having the router is the NAPT switch
        if (!naptId.equals(srcDpnId)) {
            /*
            1) Install default NAT rule from table 21 to 26
            2) Install the group which forward packet to the tunnel port for the NAPT switch.
            3) Install the flow 26 which forwards the packet to the group.
                 */
            if (!hndlTepAddOnNonNaptSwitch(srcDpnId, naptId, tunnelType, srcTepIp, destTepIp, tunnelName, routerName, routerId, bgpVpnUuId, writeFlowInvTx)) {
                LOG.error("hndlTepAddForSnatInEachRtr : Unable to process the TEP add event on NON-NAPT switch {}", srcDpnId);
                return;
            }
            return;
        }
        if (!hndlTepAddOnNaptSwitch(srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName, routerId, routerData, nextHopIp, bgpVpnUuId, extNwProvType, writeFlowInvTx)) {
            LOG.debug("hndlTepAddForSnatInEachRtr : Unable to process the TEP add event on NAPT switch {}", srcDpnId);
            return;
        }
    }
    return;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) BigInteger(java.math.BigInteger)

Example 88 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project netvirt by opendaylight.

the class NatTunnelInterfaceStateListener method hndlTepDelForDnatInEachRtr.

private void hndlTepDelForDnatInEachRtr(RoutersList router, long routerId, BigInteger tepDeletedDpnId, ProviderTypes extNwProvType) {
    // DNAT : Withdraw the routes from the BGP
    String routerName = router.getRouter();
    LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Trying to clear routes to the Floating IP " + "associated to the router {}", routerName);
    InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
    Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
    if (!optRouterPorts.isPresent()) {
        LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Could not read Router Ports data object with id: {} " + "from DNAT FloatingIpInfo", routerName);
        return;
    }
    RouterPorts routerPorts = optRouterPorts.get();
    Uuid extNwId = routerPorts.getExternalNetworkId();
    final String vpnName = NatUtil.getAssociatedVPN(dataBroker, extNwId);
    if (vpnName == null) {
        LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> No External VPN associated with Ext N/W {} for Router {}", extNwId, routerName);
        return;
    }
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    if (extNwProvType == null) {
        return;
    }
    long l3Vni = 0;
    if (extNwProvType == ProviderTypes.VXLAN) {
        // get l3Vni value for external VPN
        l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
        if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
            LOG.debug("hndlTepDelForDnatInEachRtr : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue to installing " + "NAT flows", vpnName, rd);
            l3Vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, routerId).longValue();
        }
    }
    List<Ports> interfaces = routerPorts.getPorts();
    for (Ports port : interfaces) {
        // Get the DPN on which this interface resides
        String interfaceName = port.getPortName();
        BigInteger fipCfgdDpnId = NatUtil.getDpnForInterface(interfaceService, interfaceName);
        if (fipCfgdDpnId.equals(BigInteger.ZERO)) {
            LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> Abort processing Floating ip configuration. " + "No DPN for port : {}", interfaceName);
            continue;
        }
        if (!fipCfgdDpnId.equals(tepDeletedDpnId)) {
            LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> TEP deleted DPN {} is not the DPN {} which has the " + "floating IP configured for the port: {}", tepDeletedDpnId, fipCfgdDpnId, interfaceName);
            continue;
        }
        List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
        for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
            String internalIp = intExtPortMap.getInternalIp();
            String externalIp = intExtPortMap.getExternalIp();
            externalIp = NatUtil.validateAndAddNetworkMask(externalIp);
            LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Withdrawing the FIB route to the floating IP {} " + "configured for the port: {}", externalIp, interfaceName);
            NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, externalIp, vpnName, LOG);
            long serviceId = 0;
            if (extNwProvType == ProviderTypes.VXLAN) {
                serviceId = l3Vni;
            } else {
                long label = floatingIPListener.getOperationalIpMapping(routerName, interfaceName, internalIp);
                if (label == NatConstants.INVALID_ID) {
                    LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Unable to remove the table 21 entry pushing the" + " MPLS label to the tunnel since label is invalid");
                    return;
                }
                serviceId = label;
            }
            RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(fipCfgdDpnId).setIpAddress(externalIp).setServiceId(serviceId).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.FloatingIP).build();
            Future<RpcResult<Void>> future = fibRpcService.removeFibEntry(input);
            ListenableFuture<RpcResult<Void>> listenableFuture = JdkFutureAdapters.listenInPoolThread(future);
            Futures.addCallback(listenableFuture, new FutureCallback<RpcResult<Void>>() {

                @Override
                public void onFailure(@Nonnull Throwable error) {
                    LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Error in removing the table 21 entry pushing " + "the MPLS label to the tunnel since label is invalid ", error);
                }

                @Override
                public void onSuccess(@Nonnull RpcResult<Void> result) {
                    if (result.isSuccessful()) {
                        LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> Successfully removed the entry pushing the " + "MPLS label to the tunnel");
                    } else {
                        LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Error in fib rpc call to remove the table " + "21 entry pushing the MPLS label to the tunnnel due to {}", result.getErrors());
                    }
                }
            }, MoreExecutors.directExecutor());
        }
    }
}
Also used : RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) 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) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RemoveFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInputBuilder) BigInteger(java.math.BigInteger) RemoveFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInput) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)

Example 89 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project netvirt by opendaylight.

the class NatTunnelInterfaceStateListener method hndlTepDelForSnatInEachRtr.

private void hndlTepDelForSnatInEachRtr(RoutersList router, long routerId, BigInteger dpnId, String tunnelType, String srcTepIp, String destTepIp, String tunnelName, ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
    /*SNAT :
            1) Elect a new switch as the primary NAPT
            2) Advertise the new routes to BGP for the newly elected TEP IP as the DPN IP
            3) This will make sure old routes are withdrawn and new routes are advertised.
         */
    String routerName = router.getRouter();
    LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Trying to clear routes to the External fixed IP associated " + "to the router {}", routerName);
    // Check if this is externalRouter else ignore
    InstanceIdentifier<Routers> extRoutersId = NatUtil.buildRouterIdentifier(routerName);
    Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, extRoutersId);
    if (!routerData.isPresent()) {
        LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Ignoring TEP del for router {} since its not External Router", routerName);
        return;
    }
    // Check if the DPN having the router is the NAPT switch
    BigInteger naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
    if (naptId == null || naptId.equals(BigInteger.ZERO) || !naptId.equals(dpnId)) {
        LOG.warn("hndlTepDelForSnatInEachRtr : SNAT -> Ignoring TEP delete for the DPN {} since" + " its NOT a NAPT switch for the TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and" + "TUNNEL NAME {} ", dpnId, tunnelType, srcTepIp, destTepIp, tunnelName);
        return;
    }
    if (natMode == NatMode.Conntrack) {
        natServiceManager.notify(routerData.get(), naptId, dpnId, SnatServiceManager.Action.SNAT_ROUTER_DISBL);
    } else {
        Uuid networkId = routerData.get().getNetworkId();
        if (networkId == null) {
            LOG.error("hndlTepDelForSnatInEachRtr : SNAT->Ignoring TEP delete for the DPN {} having the router {} " + "since the Router instance {} not found in ExtRouters model b/w SRC IP {} and DST " + "IP {} and TUNNEL NAME {} ", dpnId, routerData.get().getRouterName(), tunnelType, srcTepIp, destTepIp, tunnelName);
            return;
        }
        LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Router {} is associated with ext nw {}", routerId, networkId);
        Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
        Long bgpVpnId;
        if (bgpVpnUuid == null) {
            LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Internal VPN-ID {} associated to router {}", routerId, routerName);
            bgpVpnId = routerId;
            // Install default entry in FIB to SNAT table
            LOG.debug("hndlTepDelForSnatInEachRtr : Installing default route in FIB on DPN {} for router {} with" + " vpn {}...", dpnId, routerName, bgpVpnId);
            defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, writeFlowInvTx);
        } else {
            bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
            if (bgpVpnId == NatConstants.INVALID_ID) {
                LOG.error("hndlTepDelForSnatInEachRtr :SNAT->Invalid Private BGP VPN ID returned for routerName {}", routerName);
                return;
            }
            LOG.debug("hndlTepDelForSnatInEachRtr :SNAT->External BGP VPN (Private BGP) {} associated to router {}", bgpVpnId, routerName);
            // Install default entry in FIB to SNAT table
            LOG.debug("hndlTepDelForSnatInEachRtr : Installing default route in FIB on dpn {} for routerId {} " + "with vpnId {}...", dpnId, routerId, bgpVpnId);
            defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId, writeFlowInvTx);
        }
        if (routerData.get().isEnableSnat()) {
            LOG.info("hndlTepDelForSnatInEachRtr : SNAT enabled for router {}", routerId);
            long routerVpnId = routerId;
            if (bgpVpnId != NatConstants.INVALID_ID) {
                LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Private BGP VPN ID (Internal BGP VPN ID) {} " + "associated to the router {}", bgpVpnId, routerName);
                routerVpnId = bgpVpnId;
            } else {
                LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Internal L3 VPN ID (Router ID) {} " + "associated to the router {}", routerVpnId, routerName);
            }
            // Re-elect the other available switch as the NAPT switch and program the NAT flows.
            removeSNATFromDPN(dpnId, routerName, routerId, routerVpnId, networkId, extNwProvType, writeFlowInvTx);
        } else {
            LOG.info("hndlTepDelForSnatInEachRtr : SNAT is not enabled for router {} to handle addDPN event {}", routerId, dpnId);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) BigInteger(java.math.BigInteger)

Example 90 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project netvirt by opendaylight.

the class NaptEventHandler method handleEvent.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void handleEvent(final NAPTEntryEvent naptEntryEvent) {
    /*
            Flow programming logic of the OUTBOUND NAPT TABLE :
            1) Get the internal IP address, port number, router ID from the event.
            2) Use the NAPT service getExternalAddressMapping() to get the External IP and the port.
            3) Build the flow for replacing the Internal IP and port with the External IP and port.
              a) Write the matching criteria.
              b) Match the router ID in the metadata.
              d) Write the VPN ID to the metadata.
              e) Write the other data.
              f) Set the apply actions instruction with the action setfield.
            4) Write the flow to the OUTBOUND NAPT Table and forward to FIB table for routing the traffic.

            Flow programming logic of the INBOUND NAPT TABLE :
            Same as Outbound table logic except that :
            1) Build the flow for replacing the External IP and port with the Internal IP and port.
            2) Match the VPN ID in the metadata.
            3) Write the router ID to the metadata.
            5) Write the flow to the INBOUND NAPT Table and forward to FIB table for routing the traffic.
    */
    try {
        Long routerId = naptEntryEvent.getRouterId();
        LOG.trace("handleEvent : Time Elapsed before procesing snat ({}:{}) packet is {} ms," + "routerId: {},isPktProcessed:{}", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), System.currentTimeMillis() - naptEntryEvent.getObjectCreationTime(), routerId, naptEntryEvent.isPktProcessed());
        // Get the DPN ID
        BigInteger dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
        long bgpVpnId = NatConstants.INVALID_ID;
        if (dpnId == null) {
            LOG.warn("handleEvent : dpnId is null. Assuming the router ID {} as the BGP VPN ID and proceeding....", routerId);
            bgpVpnId = routerId;
            LOG.debug("handleEvent : BGP VPN ID {}", bgpVpnId);
            String vpnName = NatUtil.getRouterName(dataBroker, bgpVpnId);
            String routerName = NatUtil.getRouterIdfromVpnInstance(dataBroker, vpnName);
            if (routerName == null) {
                LOG.error("handleEvent : Unable to find router for VpnName {}", vpnName);
                return;
            }
            routerId = NatUtil.getVpnId(dataBroker, routerName);
            LOG.debug("handleEvent : Router ID {}", routerId);
            dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
            if (dpnId == null) {
                LOG.error("handleEvent : dpnId is null for the router {}", routerId);
                return;
            }
        }
        if (naptEntryEvent.getOperation() == NAPTEntryEvent.Operation.ADD) {
            LOG.debug("handleEvent : Inside Add operation of NaptEventHandler");
            // Build and install the NAPT translation flows in the Outbound and Inbound NAPT tables
            if (!naptEntryEvent.isPktProcessed()) {
                // Get the External Gateway MAC Address
                String extGwMacAddress = NatUtil.getExtGwMacAddFromRouterId(dataBroker, routerId);
                if (extGwMacAddress != null) {
                    LOG.debug("handleEvent : External Gateway MAC address {} found for External Router ID {}", extGwMacAddress, routerId);
                } else {
                    LOG.error("handleEvent : No External Gateway MAC address found for External Router ID {}", routerId);
                    return;
                }
                // Get the external network ID from the ExternalRouter model
                Uuid networkId = NatUtil.getNetworkIdFromRouterId(dataBroker, routerId);
                if (networkId == null) {
                    LOG.error("handleEvent : networkId is null");
                    return;
                }
                // Get the VPN ID from the ExternalNetworks model
                Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
                if (vpnUuid == null) {
                    LOG.error("handleEvent : vpnUuid is null");
                    return;
                }
                Long vpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
                // Get the internal IpAddress, internal port number from the event
                String internalIpAddress = naptEntryEvent.getIpAddress();
                int internalPort = naptEntryEvent.getPortNumber();
                SessionAddress internalAddress = new SessionAddress(internalIpAddress, internalPort);
                NAPTEntryEvent.Protocol protocol = naptEntryEvent.getProtocol();
                // Get the external IP address for the corresponding internal IP address
                SessionAddress externalAddress = naptManager.getExternalAddressMapping(routerId, internalAddress, naptEntryEvent.getProtocol());
                if (externalAddress == null) {
                    LOG.error("handleEvent : externalAddress is null");
                    return;
                }
                Long vpnIdFromExternalSubnet = getVpnIdFromExternalSubnet(routerId, externalAddress.getIpAddress());
                if (vpnIdFromExternalSubnet != NatConstants.INVALID_ID) {
                    vpnId = vpnIdFromExternalSubnet;
                }
                // Added External Gateway MAC Address
                Future<RpcResult<AddFlowOutput>> addFlowResult = buildAndInstallNatFlowsOptionalRpc(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnId, routerId, bgpVpnId, externalAddress, internalAddress, protocol, extGwMacAddress, true);
                final BigInteger finalDpnId = dpnId;
                final Long finalVpnId = vpnId;
                final Long finalRouterId = routerId;
                final long finalBgpVpnId = bgpVpnId;
                Futures.addCallback(JdkFutureAdapters.listenInPoolThread(addFlowResult), new FutureCallback<RpcResult<AddFlowOutput>>() {

                    @Override
                    public void onSuccess(@Nullable RpcResult<AddFlowOutput> result) {
                        LOG.debug("handleEvent : Configured inbound rule for {} to {}", internalAddress, externalAddress);
                        Future<RpcResult<AddFlowOutput>> addFlowResult = buildAndInstallNatFlowsOptionalRpc(finalDpnId, NwConstants.OUTBOUND_NAPT_TABLE, finalVpnId, finalRouterId, finalBgpVpnId, internalAddress, externalAddress, protocol, extGwMacAddress, true);
                        Futures.addCallback(JdkFutureAdapters.listenInPoolThread(addFlowResult), new FutureCallback<RpcResult<AddFlowOutput>>() {

                            @Override
                            public void onSuccess(@Nullable RpcResult<AddFlowOutput> result) {
                                LOG.debug("handleEvent : Configured outbound rule, sending packet out" + "from {} to {}", internalAddress, externalAddress);
                                prepareAndSendPacketOut(naptEntryEvent, finalRouterId);
                            }

                            @Override
                            public void onFailure(@Nonnull Throwable throwable) {
                                LOG.error("handleEvent : Error configuring outbound " + "SNAT flows using RPC for SNAT connection from {} to {}", internalAddress, externalAddress);
                            }
                        }, MoreExecutors.directExecutor());
                    }

                    @Override
                    public void onFailure(@Nonnull Throwable throwable) {
                        LOG.error("handleEvent : Error configuring inbound SNAT flows " + "using RPC for SNAT connection from {} to {}", internalAddress, externalAddress);
                    }
                }, MoreExecutors.directExecutor());
                NatPacketProcessingState state = naptEntryEvent.getState();
                if (state != null) {
                    state.setFlowInstalledTime(System.currentTimeMillis());
                }
            } else {
                prepareAndSendPacketOut(naptEntryEvent, routerId);
            }
            LOG.trace("handleEvent : Time elapsed after Processsing snat ({}:{}) packet: {}ms,isPktProcessed:{} ", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), System.currentTimeMillis() - naptEntryEvent.getObjectCreationTime(), naptEntryEvent.isPktProcessed());
        } else {
            LOG.debug("handleEvent : Inside delete Operation of NaptEventHandler");
            removeNatFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId, naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber());
            LOG.info("handleEvent : exited for removeEvent for IP {}, port {}, routerID : {}", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), routerId);
        }
    } catch (Exception e) {
        LOG.error("handleEvent :Exception in NaptEventHandler.handleEvent() payload {}", naptEntryEvent, e);
    }
}
Also used : AddFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput) Nonnull(javax.annotation.Nonnull) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) NatPacketProcessingState(org.opendaylight.netvirt.natservice.internal.NaptPacketInHandler.NatPacketProcessingState) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger) Future(java.util.concurrent.Future) FutureCallback(com.google.common.util.concurrent.FutureCallback) Nullable(javax.annotation.Nullable)

Aggregations

BigInteger (java.math.BigInteger)18 Test (org.junit.Test)17 ByteBuf (io.netty.buffer.ByteBuf)16 ArrayList (java.util.ArrayList)16 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)16 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)11 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)10 ExecutionException (java.util.concurrent.ExecutionException)9 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)9 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)9 Bgp (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp)7 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)7 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)7 List (java.util.List)6 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)6 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)5 Neighbors (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors)5 Collections (java.util.Collections)4