Search in sources :

Example 31 with Of

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.

the class NaptSwitchHA method isNaptSwitchDown.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public boolean isNaptSwitchDown(String routerName, Long routerId, BigInteger dpnId, BigInteger naptSwitch, Long routerVpnId, Collection<String> externalIpCache, boolean isClearBgpRts, WriteTransaction writeFlowInvTx) {
    externalIpsCache = externalIpCache;
    if (!naptSwitch.equals(dpnId)) {
        LOG.debug("isNaptSwitchDown : DpnId {} is not a naptSwitch {} for Router {}", dpnId, naptSwitch, routerName);
        return false;
    }
    LOG.debug("NaptSwitch {} is down for Router {}", naptSwitch, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("isNaptSwitchDown : Invalid routerId returned for routerName {}", routerName);
        return true;
    }
    Uuid networkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
    String vpnName = getExtNetworkVpnName(routerName, networkId);
    // elect a new NaptSwitch
    naptSwitch = naptSwitchSelector.selectNewNAPTSwitch(routerName);
    if (natMode == NatMode.Conntrack) {
        Routers extRouters = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
        natServiceManager.notify(extRouters, dpnId, dpnId, SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL);
        natServiceManager.notify(extRouters, naptSwitch, naptSwitch, SnatServiceManager.Action.SNAT_ALL_SWITCH_ENBL);
    } else {
        if (naptSwitch.equals(BigInteger.ZERO)) {
            LOG.warn("isNaptSwitchDown : No napt switch is elected since all the switches for router {}" + " are down. SNAT IS NOT SUPPORTED FOR ROUTER {}", routerName, routerName);
            boolean naptUpdatedStatus = updateNaptSwitch(routerName, naptSwitch);
            if (!naptUpdatedStatus) {
                LOG.debug("isNaptSwitchDown : Failed to update naptSwitch {} for router {} in ds", naptSwitch, routerName);
            }
            // clearBgpRoutes
            if (externalIpsCache != null) {
                if (vpnName != null) {
                    // if (externalIps != null) {
                    if (isClearBgpRts) {
                        LOG.debug("isNaptSwitchDown : Clearing both FIB entries and the BGP routes");
                        for (String externalIp : externalIpsCache) {
                            externalRouterListener.clearBgpRoutes(externalIp, vpnName);
                        }
                    } else {
                        LOG.debug("isNaptSwitchDown : Clearing the FIB entries but not the BGP routes");
                        String rd = NatUtil.getVpnRd(dataBroker, vpnName);
                        for (String externalIp : externalIpsCache) {
                            LOG.debug("isNaptSwitchDown : Removing Fib entry rd {} prefix {}", rd, externalIp);
                            fibManager.removeFibEntry(rd, externalIp, null);
                        }
                    }
                } else {
                    LOG.debug("isNaptSwitchDown : vpn is not associated to extn/w for router {}", routerName);
                }
            } else {
                LOG.debug("isNaptSwitchDown : No ExternalIps found for subnets under router {}, " + "no bgp routes need to be cleared", routerName);
            }
            return true;
        }
        // checking elected switch health status
        if (!getSwitchStatus(naptSwitch)) {
            LOG.error("isNaptSwitchDown : Newly elected Napt switch {} for router {} is down", naptSwitch, routerName);
            return true;
        }
        LOG.debug("isNaptSwitchDown : New NaptSwitch {} is up for Router {} and can proceed for flow installation", naptSwitch, routerName);
        // update napt model for new napt switch
        boolean naptUpdated = updateNaptSwitch(routerName, naptSwitch);
        if (naptUpdated) {
            // update group of ordinary switch point to naptSwitch tunnel port
            updateNaptSwitchBucketStatus(routerName, routerId, naptSwitch);
        } else {
            LOG.error("isNaptSwitchDown : Failed to update naptSwitch model for newNaptSwitch {} for router {}", naptSwitch, routerName);
        }
        // update table26 forward packets to table46(outbound napt table)
        FlowEntity flowEntity = buildSnatFlowEntityForNaptSwitch(naptSwitch, routerName, routerVpnId, NatConstants.ADD_FLOW);
        if (flowEntity == null) {
            LOG.error("isNaptSwitchDown : Failed to populate flowentity for router {} in naptSwitch {}", routerName, naptSwitch);
        } else {
            LOG.debug("isNaptSwitchDown : Successfully installed flow in naptSwitch {} for router {}", naptSwitch, routerName);
            mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
        }
        installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, writeFlowInvTx);
        boolean flowInstalledStatus = handleNatFlowsInNewNaptSwitch(routerName, routerId, dpnId, naptSwitch, routerVpnId, networkId);
        if (flowInstalledStatus) {
            LOG.debug("isNaptSwitchDown :Installed all active session flows in newNaptSwitch {} for routerName {}", naptSwitch, routerName);
        } else {
            LOG.error("isNaptSwitchDown : Failed to install flows in newNaptSwitch {} for routerId {}", naptSwitch, routerId);
        }
        // remove group in new naptswitch, coz this switch acted previously as ordinary switch
        long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
        GroupEntity groupEntity = null;
        try {
            groupEntity = MDSALUtil.buildGroupEntity(naptSwitch, groupId, routerName, GroupTypes.GroupAll, Collections.emptyList());
            LOG.info("isNaptSwitchDown : Removing NAPT Group in new naptSwitch {}", naptSwitch);
            mdsalManager.removeGroup(groupEntity);
        } catch (Exception ex) {
            LOG.error("isNaptSwitchDown : Failed to remove group in new naptSwitch {}", groupEntity, ex);
        }
    }
    return true;
}
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) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) ExecutionException(java.util.concurrent.ExecutionException) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 32 with Of

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.

the class AbstractAclServiceImpl method syncRemoteAclTable.

private void syncRemoteAclTable(String portId, Uuid acl, Integer aclTag, List<AllowedAddressPairs> aaps, int addOrRemove) {
    Map<String, Set<AclInterface>> mapAclWithPortSet = aclDataUtil.getRemoteAclInterfaces(acl, this.direction);
    Set<BigInteger> dpns = collectDpns(mapAclWithPortSet);
    for (AllowedAddressPairs aap : aaps) {
        if (!AclServiceUtils.isNotIpAllNetwork(aap)) {
            continue;
        }
        if (aclServiceUtils.skipDeleteInCaseOfOverlappingIP(portId, acl, aap.getIpAddress(), addOrRemove)) {
            LOG.debug("Skipping delete of IP={} in remote ACL table for remoteAclId={}, portId={}", aap.getIpAddress(), portId, acl.getValue());
            continue;
        }
        for (BigInteger dpId : dpns) {
            programRemoteAclTableFlow(dpId, aclTag, aap, addOrRemove);
        }
    }
}
Also used : SortedSet(java.util.SortedSet) Set(java.util.Set) HashSet(java.util.HashSet) BigInteger(java.math.BigInteger) AllowedAddressPairs(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs)

Example 33 with Of

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.

the class AbstractAclServiceImpl method programAclRules.

/**
 * Programs the acl custom rules.
 *
 * @param port acl interface
 * @param aclUuidList the list of acl uuid to be applied
 * @param addOrRemove whether to delete or add flow
 * @return program succeeded
 */
protected boolean programAclRules(AclInterface port, List<Uuid> aclUuidList, int addOrRemove) {
    BigInteger dpId = port.getDpId();
    LOG.debug("Applying custom rules on DpId {}, lportTag {}", dpId, port.getLPortTag());
    if (aclUuidList == null || dpId == null) {
        LOG.warn("{} ACL parameters can not be null. dpId={}, aclUuidList={}", this.directionString, dpId, aclUuidList);
        return false;
    }
    for (Uuid aclUuid : aclUuidList) {
        Acl acl = this.aclDataUtil.getAcl(aclUuid.getValue());
        if (null == acl) {
            LOG.warn("The ACL {} not found in cache", aclUuid.getValue());
            continue;
        }
        AccessListEntries accessListEntries = acl.getAccessListEntries();
        List<Ace> aceList = accessListEntries.getAce();
        for (Ace ace : aceList) {
            programAceRule(port, aclUuid.getValue(), ace, addOrRemove);
        }
    }
    return true;
}
Also used : Ace(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger) Acl(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl) AccessListEntries(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.AccessListEntries)

Example 34 with Of

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.

the class NexthopManager method removeLocalNextHop.

public void removeLocalNextHop(BigInteger dpnId, Long vpnId, String ipNextHopAddress, String ipPrefixAddress) {
    String ipPrefixStr = vpnId + ipPrefixAddress;
    VpnNexthop prefixNh = null;
    synchronized (ipPrefixStr.intern()) {
        prefixNh = getVpnNexthop(vpnId, ipPrefixAddress);
    }
    String ipAddress = prefixNh != null ? ipPrefixAddress : ipNextHopAddress;
    String nextHopLockStr = vpnId + ipAddress;
    synchronized (nextHopLockStr.intern()) {
        VpnNexthop nh = getVpnNexthop(vpnId, ipAddress);
        if (nh != null) {
            int newFlowrefCnt = nh.getFlowrefCount() - 1;
            if (newFlowrefCnt == 0) {
                // remove the group only if there are no more flows using this group
                GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, nh.getEgressPointer(), ipAddress, GroupTypes.GroupAll, Collections.EMPTY_LIST);
                // remove Group ...
                mdsalApiManager.removeGroup(groupEntity);
                // update MD-SAL DS
                removeVpnNexthopFromDS(vpnId, ipAddress);
                // release groupId
                removeNextHopPointer(getNextHopKey(vpnId, ipAddress));
                LOG.debug("Local Next hop {} for {} {} on dpn {} successfully deleted", nh.getEgressPointer(), vpnId, ipAddress, dpnId);
            } else {
                // just update the flowrefCount of the vpnNexthop
                VpnNexthop currNh = new VpnNexthopBuilder().setKey(new VpnNexthopKey(ipAddress)).setFlowrefCount(newFlowrefCnt).build();
                LOG.trace("Updating vpnnextHop {} for refCount {} to Operational DS", currNh, newFlowrefCnt);
                MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, getVpnNextHopIdentifier(vpnId, ipAddress), currNh);
            }
        } else {
            // throw error
            LOG.error("Local Next hop for Prefix {} VpnId {} on dpn {} not deleted", ipAddress, vpnId, dpnId);
        }
    }
}
Also used : VpnNexthopKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopKey) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) VpnNexthop(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop) VpnNexthopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopBuilder)

Example 35 with Of

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.

the class ElanL2GatewayUtils method installDmacFlowsOnDpn.

/**
 * Install dmac flows on dpn.
 *
 * @param dpnId
 *            the dpn id
 * @param l2gwDevice
 *            the l2gw device
 * @param elan
 *            the elan
 * @param interfaceName
 *            the interface name
 * @throws ElanException in case of issues creating the flow objects
 */
public void installDmacFlowsOnDpn(BigInteger dpnId, L2GatewayDevice l2gwDevice, ElanInstance elan, String interfaceName) throws ElanException {
    String elanName = elan.getElanInstanceName();
    Collection<LocalUcastMacs> l2gwDeviceLocalMacs = l2gwDevice.getUcastLocalMacs();
    if (!l2gwDeviceLocalMacs.isEmpty()) {
        for (LocalUcastMacs localUcastMac : l2gwDeviceLocalMacs) {
            elanDmacUtils.installDmacFlowsToExternalRemoteMacInBatch(dpnId, l2gwDevice.getHwvtepNodeId(), elan.getElanTag(), ElanUtils.getVxlanSegmentationId(elan), localUcastMac.getMacEntryKey().getValue(), elanName, interfaceName);
        }
        LOG.debug("Installing L2gw device [{}] local macs [size: {}] in dpn [{}] for elan [{}]", l2gwDevice.getHwvtepNodeId(), l2gwDeviceLocalMacs.size(), dpnId, elanName);
    }
}
Also used : LocalUcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs)

Aggregations

ArrayList (java.util.ArrayList)376 Test (org.junit.Test)275 ByteBuf (io.netty.buffer.ByteBuf)262 ExecutionException (java.util.concurrent.ExecutionException)130 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)123 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)121 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)114 InstructionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder)100 InstructionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder)99 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)98 ApplyActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder)93 ApplyActionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder)91 SetVlanIdActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder)85 GroupActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder)83 BigInteger (java.math.BigInteger)82 List (java.util.List)82 DropActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder)82 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)82 ControllerActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder)81 DropAction (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction)81