Search in sources :

Example 66 with GroupId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId 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)

Example 67 with GroupId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId in project netvirt by opendaylight.

the class ExternalNetworkGroupInstaller method removeExtNetGroupEntries.

public void removeExtNetGroupEntries(Subnetmap subnetMap) {
    if (subnetMap == null) {
        return;
    }
    String subnetName = subnetMap.getId().getValue();
    Uuid networkId = subnetMap.getNetworkId();
    if (networkId == null) {
        LOG.error("removeExtNetGroupEntries : No external network associated subnet id {}", subnetName);
        return;
    }
    Collection<String> extInterfaces = elanService.getExternalElanInterfaces(networkId.getValue());
    if (extInterfaces == null || extInterfaces.isEmpty()) {
        LOG.debug("removeExtNetGroupEntries : No external ELAN interfaces attached to network {} subnet {}", networkId, subnetName);
        return;
    }
    long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(subnetName), idManager);
    for (String extInterface : extInterfaces) {
        GroupEntity groupEntity = buildEmptyExtNetGroupEntity(subnetName, groupId, extInterface);
        if (groupEntity != null) {
            LOG.info("removeExtNetGroupEntries : Remove ext-net Group: id {}, subnet id {}", groupId, subnetName);
            NatServiceCounters.remove_external_network_group.inc();
            mdsalManager.syncRemoveGroup(groupEntity);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity)

Example 68 with GroupId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId in project netvirt by opendaylight.

the class ExternalNetworkGroupInstaller method installExtNetGroupEntries.

private void installExtNetGroupEntries(Subnetmap subnetMap, String macAddress) {
    String subnetName = subnetMap.getId().getValue();
    Uuid networkId = subnetMap.getNetworkId();
    if (networkId == null) {
        LOG.error("installExtNetGroupEntries : No network associated subnet id {}", subnetName);
        return;
    }
    Collection<String> extInterfaces = elanService.getExternalElanInterfaces(networkId.getValue());
    if (extInterfaces == null || extInterfaces.isEmpty()) {
        LOG.trace("installExtNetGroupEntries : No external ELAN interfaces attached to network:{},subnet {}", networkId, subnetName);
        return;
    }
    long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(subnetName), idManager);
    LOG.info("installExtNetGroupEntries : Installing ext-net group {} entry for subnet {} with macAddress {} " + "(extInterfaces: {})", groupId, subnetName, macAddress, Arrays.toString(extInterfaces.toArray()));
    for (String extInterface : extInterfaces) {
        BigInteger dpId = NatUtil.getDpnForInterface(interfaceManager, extInterface);
        if (BigInteger.ZERO.equals(dpId)) {
            LOG.info("installExtNetGroupEntries: No DPN for interface {}. NAT ext-net flow will not be installed " + "for subnet {}", extInterface, subnetName);
            return;
        }
        installExtNetGroupEntry(groupId, subnetName, extInterface, macAddress, dpId);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger)

Example 69 with GroupId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId in project netvirt by opendaylight.

the class FibUtil method updateLbGroupInfo.

public static void updateLbGroupInfo(BigInteger dpnId, String destinationIp, String groupIdKey, String groupId, WriteTransaction tx) {
    InstanceIdentifier<DpnLbNexthops> id = getDpnLbNexthopsIdentifier(dpnId, destinationIp);
    DpnLbNexthops dpnToLbNextHop = buildDpnLbNextHops(dpnId, destinationIp, groupIdKey);
    tx.merge(LogicalDatastoreType.OPERATIONAL, id, dpnToLbNextHop);
    InstanceIdentifier<Nexthops> nextHopsId = getNextHopsIdentifier(groupIdKey);
    Nexthops nextHopsToGroupId = buildNextHops(dpnId, groupIdKey, groupId);
    tx.merge(LogicalDatastoreType.OPERATIONAL, nextHopsId, nextHopsToGroupId);
}
Also used : DpnLbNexthops(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpid.l3vpn.lb.nexthops.DpnLbNexthops) DpidL3vpnLbNexthops(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.DpidL3vpnLbNexthops) Nexthops(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.l3vpn.lb.nexthops.Nexthops) DpnLbNexthops(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpid.l3vpn.lb.nexthops.DpnLbNexthops) L3vpnLbNexthops(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.L3vpnLbNexthops)

Example 70 with GroupId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId in project netvirt by opendaylight.

the class NexthopManager method updateDcGwLoadBalancingGroup.

/**
 * This method is invoked when the tunnel status is updated.
 * The bucket is directly removed/added based on the operational status of the tunnel.
 */
public void updateDcGwLoadBalancingGroup(List<String> availableDcGws, BigInteger dpnId, String destinationIp, boolean isTunnelUp) {
    Preconditions.checkNotNull(availableDcGws, "There are no dc-gws present");
    WriteTransaction configTx = dataBroker.newWriteOnlyTransaction();
    // TODO : Place the logic to construct all possible DC-GW combination here.
    int bucketId = availableDcGws.indexOf(destinationIp);
    Optional<DpnLbNexthops> dpnLbNextHops = fibUtil.getDpnLbNexthops(dpnId, destinationIp);
    if (!dpnLbNextHops.isPresent()) {
        return;
    }
    List<String> nextHopKeys = dpnLbNextHops.get().getNexthopKey();
    nextHopKeys.forEach(nextHopKey -> {
        Optional<Nexthops> optionalNextHops = fibUtil.getNexthops(nextHopKey);
        if (!optionalNextHops.isPresent()) {
            return;
        }
        Nexthops nexthops = optionalNextHops.get();
        final String groupId = nexthops.getGroupId();
        final long groupIdValue = Long.parseLong(groupId);
        if (isTunnelUp) {
            Bucket bucket = buildBucketForDcGwLbGroup(destinationIp, dpnId, bucketId);
            LOG.trace("Added bucket {} to group {} on dpn {}.", bucket, groupId, dpnId);
            mdsalApiManager.addBucketToTx(dpnId, groupIdValue, bucket, configTx);
        } else {
            LOG.trace("Removed bucketId {} from group {} on dpn {}.", bucketId, groupId, dpnId);
            mdsalApiManager.removeBucketToTx(dpnId, groupIdValue, bucketId, configTx);
        }
    });
    configTx.submit();
    return;
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DpnLbNexthops(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpid.l3vpn.lb.nexthops.DpnLbNexthops) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) VpnNexthops(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.VpnNexthops) Nexthops(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.l3vpn.lb.nexthops.Nexthops) DpnLbNexthops(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpid.l3vpn.lb.nexthops.DpnLbNexthops)

Aggregations

ArrayList (java.util.ArrayList)41 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId)36 Test (org.junit.Test)28 Bucket (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket)27 GroupId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId)22 Group (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group)21 BigInteger (java.math.BigInteger)19 ActionGroup (org.opendaylight.genius.mdsalutil.actions.ActionGroup)18 GroupBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder)12 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)11 BucketsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder)10 BucketBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.BucketBuilder)10 ByteBuf (io.netty.buffer.ByteBuf)9 GroupKey (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey)9 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)8 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)8 AddGroupInput (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput)8 AddGroupInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder)8 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)7 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)6