Search in sources :

Example 6 with BucketInfo

use of org.opendaylight.genius.mdsalutil.BucketInfo in project netvirt by opendaylight.

the class VxlanGreConntrackBasedSnatService method installSnatMissEntry.

protected void installSnatMissEntry(BigInteger dpnId, Long routerId, String routerName, BigInteger primarySwitchId, int addOrRemove) {
    LOG.debug("installSnatMissEntry : Installing SNAT miss entry in switch {}", dpnId);
    List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
    String ifNamePrimary = getTunnelInterfaceName(dpnId, primarySwitchId);
    List<BucketInfo> listBucketInfo = new ArrayList<>();
    if (ifNamePrimary != null) {
        LOG.debug("installSnatMissEntry : On Non- Napt switch , Primary Tunnel interface is {}", ifNamePrimary);
        listActionInfoPrimary = NatUtil.getEgressActionsForInterface(interfaceManager, ifNamePrimary, routerId);
    }
    BucketInfo bucketPrimary = new BucketInfo(listActionInfoPrimary);
    listBucketInfo.add(0, bucketPrimary);
    LOG.debug("installSnatMissEntry : installSnatMissEntry called for dpnId {} with primaryBucket {} ", dpnId, listBucketInfo.get(0));
    // Install the select group
    long groupId = createGroupId(getGroupIdKey(routerName));
    GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, listBucketInfo);
    LOG.debug("installSnatMissEntry : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
    mdsalManager.installGroup(groupEntity);
    // Install miss entry pointing to group
    LOG.debug("installSnatMissEntry : buildSnatFlowEntity is called for dpId {}, routerName {} and groupId {}", dpnId, routerName, groupId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchEthernetType(0x0800L));
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId), MetaDataUtil.METADATA_MASK_VRFID));
    List<ActionInfo> actionsInfo = new ArrayList<>();
    BigInteger tunnelId = BigInteger.valueOf(routerId);
    if (elanManager.isOpenStackVniSemanticsEnforced()) {
        tunnelId = NatOverVxlanUtil.getRouterVni(idManager, routerName, routerId);
    }
    actionsInfo.add(new ActionSetFieldTunnelId(tunnelId));
    LOG.debug("AbstractSnatService : Setting the tunnel to the list of action infos {}", actionsInfo);
    actionsInfo.add(new ActionGroup(groupId));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionApplyActions(actionsInfo));
    String flowRef = getFlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
    syncFlow(dpnId, NwConstants.PSNAT_TABLE, flowRef, NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions, addOrRemove);
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) BigInteger(java.math.BigInteger) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 7 with BucketInfo

use of org.opendaylight.genius.mdsalutil.BucketInfo in project netvirt by opendaylight.

the class NaptSwitchHA method handleGroupInNeighborSwitches.

@Nonnull
public List<BucketInfo> handleGroupInNeighborSwitches(BigInteger dpnId, String routerName, long routerId, BigInteger naptSwitch) {
    List<BucketInfo> listBucketInfo = new ArrayList<>();
    String ifNamePrimary;
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("handleGroupInNeighborSwitches : Invalid routerId returned for routerName {}", routerName);
        return listBucketInfo;
    }
    ifNamePrimary = getTunnelInterfaceName(dpnId, naptSwitch);
    if (ifNamePrimary != null) {
        LOG.debug("handleGroupInNeighborSwitches : TunnelInterface {} between ordinary switch {} and naptSwitch {}", ifNamePrimary, dpnId, naptSwitch);
        List<ActionInfo> listActionInfoPrimary = NatUtil.getEgressActionsForInterface(interfaceManager, ifNamePrimary, routerId);
        BucketInfo bucketPrimary = new BucketInfo(listActionInfoPrimary);
        listBucketInfo.add(bucketPrimary);
    } else {
        LOG.debug("handleGroupInNeighborSwitches : No TunnelInterface between ordinary switch {} and naptSwitch {}", dpnId, naptSwitch);
    }
    return listBucketInfo;
}
Also used : ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) Nonnull(javax.annotation.Nonnull)

Example 8 with BucketInfo

use of org.opendaylight.genius.mdsalutil.BucketInfo in project netvirt by opendaylight.

the class AbstractSnatService method installSnatMissEntry.

protected void installSnatMissEntry(BigInteger dpnId, Long routerId, String routerName, BigInteger primarySwitchId, String externalIp, long extSubnetId, int addOrRemove) {
    LOG.debug("installSnatMissEntry : Installing SNAT miss entry in switch {}", dpnId);
    List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
    String ifNamePrimary = getTunnelInterfaceName(dpnId, primarySwitchId);
    List<BucketInfo> listBucketInfo = new ArrayList<>();
    if (ifNamePrimary != null) {
        LOG.debug("installSnatMissEntry : On Non- Napt switch , Primary Tunnel interface is {}", ifNamePrimary);
        listActionInfoPrimary = NatUtil.getEgressActionsForInterface(interfaceManager, ifNamePrimary, routerId);
    }
    BucketInfo bucketPrimary = new BucketInfo(listActionInfoPrimary);
    listBucketInfo.add(0, bucketPrimary);
    LOG.debug("installSnatMissEntry : installSnatMissEntry called for dpnId {} with primaryBucket {} ", dpnId, listBucketInfo.get(0));
    // Install the select group
    long groupId = createGroupId(getGroupIdKey(routerName));
    GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, listBucketInfo);
    LOG.debug("installSnatMissEntry : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
    mdsalManager.installGroup(groupEntity);
    // Install miss entry pointing to group
    LOG.debug("installSnatMissEntry : buildSnatFlowEntity is called for dpId {}, routerName {} and groupId {}", dpnId, routerName, groupId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchEthernetType(0x0800L));
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId), MetaDataUtil.METADATA_MASK_VRFID));
    List<ActionInfo> actionsInfo = new ArrayList<>();
    actionsInfo.add(new ActionSetFieldTunnelId(BigInteger.valueOf(routerId)));
    LOG.debug("installSnatMissEntry : Setting the tunnel to the list of action infos {}", actionsInfo);
    actionsInfo.add(new ActionGroup(groupId));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionApplyActions(actionsInfo));
    String flowRef = getFlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
    syncFlow(dpnId, NwConstants.PSNAT_TABLE, flowRef, NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions, addOrRemove);
    // Install the FIB entry for traffic destined to SNAT IP in Non-NAPT switch.
    matches = new ArrayList<>();
    actionsInfo = new ArrayList<>();
    matches.add(new MatchEthernetType(0x0800L));
    if (addOrRemove == NwConstants.ADD_FLOW) {
        if (extSubnetId == NatConstants.INVALID_ID) {
            LOG.error("installSnatMissEntry : external subnet id is invalid.");
            return;
        }
        actionsInfo.add(new ActionSetFieldTunnelId(BigInteger.valueOf(extSubnetId)));
        matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(extSubnetId), MetaDataUtil.METADATA_MASK_VRFID));
    }
    matches.add(new MatchIpv4Destination(externalIp, "32"));
    LOG.debug("installSnatMissEntry : Setting the tunnel to the list of action infos {}", actionsInfo);
    actionsInfo.add(new ActionGroup(groupId));
    instructions = new ArrayList<>();
    instructions.add(new InstructionApplyActions(actionsInfo));
    flowRef = getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, routerId);
    flowRef = flowRef + "inboundmiss" + externalIp;
    syncFlow(dpnId, NwConstants.L3_FIB_TABLE, flowRef, NatConstants.SNAT_FIB_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions, addOrRemove);
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 9 with BucketInfo

use of org.opendaylight.genius.mdsalutil.BucketInfo in project netvirt by opendaylight.

the class ExternalNetworksChangeListenerTest method testSnatFlowEntity.

@Test
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void testSnatFlowEntity() {
    FlowEntity flowMock = mock(FlowEntity.class);
    final short snatTable = 40;
    final int defaultSnatFlowPriority = 0;
    final String flowidSeparator = ".";
    String routerName = "200";
    List<BucketInfo> bucketInfo = new ArrayList<>();
    List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
    listActionInfoPrimary.add(new ActionOutput(new Uri("3")));
    BucketInfo bucketPrimary = new BucketInfo(listActionInfoPrimary);
    List<ActionInfo> listActionInfoSecondary = new ArrayList<>();
    listActionInfoSecondary.add(new ActionOutput(new Uri("4")));
    BucketInfo bucketSecondary = new BucketInfo(listActionInfoPrimary);
    bucketInfo.add(0, bucketPrimary);
    bucketInfo.add(1, bucketSecondary);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    List<InstructionInfo> instructions = new ArrayList<>();
    List<ActionInfo> actionsInfos = new ArrayList<>();
    long groupId = 300;
    actionsInfos.add(new ActionGroup(groupId));
    instructions.add(new InstructionApplyActions(actionsInfos));
    BigInteger dpnId = new BigInteger("100");
    long routerId = 200;
    String snatFlowidPrefix = "SNAT.";
    String flowRef = snatFlowidPrefix + dpnId + flowidSeparator + snatTable + flowidSeparator + routerId;
    BigInteger cookieSnat = NatUtil.getCookieSnatFlow(routerId);
    try {
        PowerMockito.when(MDSALUtil.class, "buildFlowEntity", dpnId, snatTable, flowRef, defaultSnatFlowPriority, flowRef, 0, 0, cookieSnat, matches, instructions).thenReturn(flowMock);
    } catch (Exception e) {
        // Test failed anyways
        assertEquals("true", "false");
    }
/* TODO : Fix this to mock it properly when it reads DS
        extNetworks.buildSnatFlowEntity(dpnId, routerName, groupId);
        PowerMockito.verifyStatic(); */
}
Also used : MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) BigInteger(java.math.BigInteger) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) ActionOutput(org.opendaylight.genius.mdsalutil.actions.ActionOutput) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with BucketInfo

use of org.opendaylight.genius.mdsalutil.BucketInfo in project netvirt by opendaylight.

the class NexthopManager method createLocalNextHop.

public long createLocalNextHop(long vpnId, BigInteger dpnId, String ifName, String ipNextHopAddress, String ipPrefixAddress, String gwMacAddress, String jobKey) {
    String vpnName = fibUtil.getVpnNameFromId(vpnId);
    if (vpnName == null) {
        return 0;
    }
    String macAddress = fibUtil.getMacAddressFromPrefix(ifName, vpnName, ipPrefixAddress);
    String ipAddress = macAddress != null ? ipPrefixAddress : ipNextHopAddress;
    long groupId = createNextHopPointer(getNextHopKey(vpnId, ipAddress));
    if (groupId == 0) {
        LOG.error("Unable to allocate groupId for vpnId {} , prefix {}  IntfName {}, nextHopAddr {}", vpnId, ipAddress, ifName, ipNextHopAddress);
        return groupId;
    }
    String nextHopLockStr = vpnId + ipAddress;
    jobCoordinator.enqueueJob(jobKey, () -> {
        synchronized (nextHopLockStr.intern()) {
            VpnNexthop nexthop = getVpnNexthop(vpnId, ipAddress);
            LOG.trace("nexthop: {} retrieved for vpnId {}, prefix {}, ifName {} on dpn {}", nexthop, vpnId, ipAddress, ifName, dpnId);
            if (nexthop == null) {
                String encMacAddress = macAddress == null ? fibUtil.getMacAddressFromPrefix(ifName, vpnName, ipAddress) : macAddress;
                List<BucketInfo> listBucketInfo = new ArrayList<>();
                List<ActionInfo> listActionInfo = new ArrayList<>();
                int actionKey = 0;
                // MAC re-write
                if (encMacAddress != null) {
                    if (gwMacAddress != null) {
                        LOG.trace("The Local NextHop Group Source Mac {} for VpnInterface {} on VPN {}", gwMacAddress, ifName, vpnId);
                        listActionInfo.add(new ActionSetFieldEthernetSource(actionKey++, new MacAddress(gwMacAddress)));
                    }
                    listActionInfo.add(new ActionSetFieldEthernetDestination(actionKey++, new MacAddress(encMacAddress)));
                // listActionInfo.add(0, new ActionPopMpls());
                } else {
                    // FIXME: Log message here.
                    LOG.debug("mac address for new local nexthop is null");
                }
                listActionInfo.addAll(getEgressActionsForInterface(ifName, actionKey));
                BucketInfo bucket = new BucketInfo(listActionInfo);
                listBucketInfo.add(bucket);
                GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, ipAddress, GroupTypes.GroupAll, listBucketInfo);
                LOG.trace("Install LNH Group: id {}, mac address {}, interface {} for prefix {}", groupId, encMacAddress, ifName, ipAddress);
                // Try to install group directly on the DPN bypassing the FRM, in order to avoid waiting for the
                // group to get installed before programming the flows
                installGroupOnDpn(groupId, dpnId, ipAddress, listBucketInfo, getNextHopKey(vpnId, ipAddress), GroupTypes.GroupAll);
                // install Group
                mdsalApiManager.syncInstallGroup(groupEntity);
                // update MD-SAL DS
                addVpnNexthopToDS(dpnId, vpnId, ipAddress, groupId);
            } else {
                // nexthop exists already; a new flow is going to point to
                // it, increment the flowrefCount by 1
                int flowrefCnt = nexthop.getFlowrefCount() + 1;
                VpnNexthop nh = new VpnNexthopBuilder().setKey(new VpnNexthopKey(ipAddress)).setFlowrefCount(flowrefCnt).build();
                LOG.trace("Updating vpnnextHop {} for refCount {} to Operational DS", nh, flowrefCnt);
                MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, getVpnNextHopIdentifier(vpnId, ipAddress), nh);
            }
        }
        return Collections.emptyList();
    });
    return groupId;
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) VpnNexthop(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) VpnNexthopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopBuilder) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) VpnNexthopKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopKey) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo)

Aggregations

BucketInfo (org.opendaylight.genius.mdsalutil.BucketInfo)19 ArrayList (java.util.ArrayList)14 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)13 BigInteger (java.math.BigInteger)7 ActionGroup (org.opendaylight.genius.mdsalutil.actions.ActionGroup)6 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)5 GroupEntity (org.opendaylight.genius.mdsalutil.GroupEntity)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)3 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)3 ActionNxResubmit (org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit)3 ActionOutput (org.opendaylight.genius.mdsalutil.actions.ActionOutput)3 ActionSetFieldEthernetDestination (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination)3 ActionSetFieldTunnelId (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId)3 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)3 MDSALUtil (org.opendaylight.genius.mdsalutil.MDSALUtil)2 ActionPushVlan (org.opendaylight.genius.mdsalutil.actions.ActionPushVlan)2 ActionSetFieldEthernetSource (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource)2 ActionSetFieldVlanVid (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldVlanVid)2 MatchEthernetType (org.opendaylight.genius.mdsalutil.matches.MatchEthernetType)2