Search in sources :

Example 6 with ExtRouters

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters in project netvirt by opendaylight.

the class NeutronvpnNatManager method handleSubnetsForExternalRouter.

public void handleSubnetsForExternalRouter(Uuid routerId) {
    InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
    try {
        Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
        LOG.trace("Updating Internal subnets for Routers node: {}", routerId.getValue());
        RoutersBuilder builder = null;
        if (optionalRouters.isPresent()) {
            builder = new RoutersBuilder(optionalRouters.get());
        } else {
            LOG.debug("No Routers element found for router {}", routerId.getValue());
            return;
        }
        List<Uuid> subList = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
        builder.setSubnetIds(subList);
        Routers routerss = builder.build();
        // Add Routers object to the ExtRouters list
        LOG.trace("Updating extrouters {}", routerss);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, routerss);
        LOG.trace("Updated successfully Routers to CONFIG Datastore");
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Updation of internal subnets for extrouters failed for router {}", routerId.getValue(), ex);
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) RoutersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder) 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)

Example 7 with ExtRouters

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters in project netvirt by opendaylight.

the class NeutronPortChangeListener method setExternalGwMac.

private void setExternalGwMac(Port routerGwPort, Uuid routerId) {
    // During full-sync networking-odl syncs routers before ports. As such,
    // the MAC of the router's gw port is not available to be set when the
    // router is written. We catch that here.
    InstanceIdentifier<Routers> routersId = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
    Optional<Routers> optionalRouter = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId);
    if (!optionalRouter.isPresent()) {
        return;
    }
    Routers extRouters = optionalRouter.get();
    if (extRouters.getExtGwMacAddress() != null) {
        return;
    }
    RoutersBuilder builder = new RoutersBuilder(extRouters);
    builder.setExtGwMacAddress(routerGwPort.getMacAddress().getValue());
    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId, builder.build());
}
Also used : RoutersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)

Example 8 with ExtRouters

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters in project netvirt by opendaylight.

the class VpnUtil method getAssociatedExternalRouter.

public static String getAssociatedExternalRouter(DataBroker dataBroker, String extIp) {
    InstanceIdentifier<ExtRouters> extRouterInstanceIndentifier = InstanceIdentifier.builder(ExtRouters.class).build();
    Optional<ExtRouters> extRouterData = read(dataBroker, LogicalDatastoreType.CONFIGURATION, extRouterInstanceIndentifier);
    if (extRouterData.isPresent()) {
        for (Routers routerData : extRouterData.get().getRouters()) {
            List<ExternalIps> externalIps = routerData.getExternalIps();
            for (ExternalIps externalIp : externalIps) {
                if (externalIp.getIpAddress().equals(extIp)) {
                    return routerData.getRouterName();
                }
            }
        }
    }
    return null;
}
Also used : Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 9 with ExtRouters

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters 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 10 with ExtRouters

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters in project netvirt by opendaylight.

the class RouterDpnChangeListener method handleSNATForDPN.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
void handleSNATForDPN(BigInteger dpnId, String routerName, long routerId, Long routerVpnId, WriteTransaction writeFlowInvTx, WriteTransaction removeFlowInvTx, ProviderTypes extNwProvType) {
    // Check if primary and secondary switch are selected, If not select the role
    // Install select group to NAPT switch
    // Install default miss entry to NAPT switch
    BigInteger naptSwitch;
    try {
        BigInteger naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
        if (naptId == null || naptId.equals(BigInteger.ZERO) || !naptSwitchHA.getSwitchStatus(naptId)) {
            LOG.debug("handleSNATForDPN : No NaptSwitch is selected for router {}", routerName);
            naptSwitch = dpnId;
            boolean naptstatus = naptSwitchHA.updateNaptSwitch(routerName, naptSwitch);
            if (!naptstatus) {
                LOG.error("handleSNATForDPN : Failed to update newNaptSwitch {} for routername {}", naptSwitch, routerName);
                return;
            }
            LOG.debug("handleSNATForDPN : Switch {} is elected as NaptSwitch for router {}", dpnId, routerName);
            // When NAPT switch is elected during first VM comes up for the given Router
            if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
                NatOverVxlanUtil.validateAndCreateVxlanVniPool(dataBroker, nvpnManager, idManager, NatConstants.ODL_VNI_POOL_NAME);
            }
            Routers extRouters = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
            if (extRouters != null) {
                NatUtil.createRouterIdsConfigDS(dataBroker, routerId, routerName);
                naptSwitchHA.subnetRegisterMapping(extRouters, routerId);
            }
            naptSwitchHA.installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, writeFlowInvTx);
            // Install miss entry (table 26) pointing to table 46
            FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId, NatConstants.ADD_FLOW);
            if (flowEntity == null) {
                LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
                return;
            }
            LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {}", dpnId, routerName);
            mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
            // Removing primary flows from old napt switch
            if (naptId != null && !naptId.equals(BigInteger.ZERO)) {
                LOG.debug("handleSNATForDPN : Removing primary flows from old napt switch {} for router {}", naptId, routerName);
                naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, naptId, null, removeFlowInvTx);
            }
        } else if (naptId.equals(dpnId)) {
            LOG.debug("handleSNATForDPN : NaptSwitch {} gone down during cluster reboot came alive", naptId);
        } else {
            naptSwitch = naptId;
            LOG.debug("handleSNATForDPN : Napt switch with Id {} is already elected for router {}", naptId, routerName);
            // installing group
            List<BucketInfo> bucketInfo = naptSwitchHA.handleGroupInNeighborSwitches(dpnId, routerName, routerId, naptSwitch);
            naptSwitchHA.installSnatGroupEntry(dpnId, bucketInfo, routerName);
            // Install miss entry (table 26) pointing to group
            long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
            FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId, NatConstants.ADD_FLOW);
            if (flowEntity == null) {
                LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {} groupId {}", routerName, dpnId, groupId);
                return;
            }
            LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {} group {}", dpnId, routerName, groupId);
            mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
        }
    } catch (Exception ex) {
        LOG.error("handleSNATForDPN : Exception in handleSNATForDPN", ex);
    }
}
Also used : Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) RouterDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList) DpnVpninterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList) List(java.util.List) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Aggregations

Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)11 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)10 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)8 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)7 RoutersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder)6 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)4 ArrayList (java.util.ArrayList)3 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)3 ExternalFixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps)3 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)3 BigInteger (java.math.BigInteger)2 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)2 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)2 ExtRouters (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters)2 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)2 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)2 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)2 NetworksBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)2 NetworksKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey)2 Inet6Address (java.net.Inet6Address)1