Search in sources :

Example 31 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class SubnetRoutePacketInHandler method getTargetSubnetForPacketOut.

// return only the first VPN subnetopdataentry
private static SubnetOpDataEntry getTargetSubnetForPacketOut(DataBroker broker, long elanTag, int ipAddress) {
    ElanTagName elanInfo = VpnUtil.getElanInfoByElanTag(broker, elanTag);
    if (elanInfo == null) {
        LOG.error("{} getTargetDpnForPacketOut: Unable to retrieve ElanInfo for elanTag {}", LOGGING_PREFIX, elanTag);
        return null;
    }
    Optional<NetworkMap> optionalNetworkMap = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, VpnUtil.buildNetworkMapIdentifier(new Uuid(elanInfo.getName())));
    if (!optionalNetworkMap.isPresent()) {
        LOG.debug("{} getTargetDpnForPacketOut: No network map found for elan info {}", LOGGING_PREFIX, elanInfo.getName());
        return null;
    }
    List<Uuid> subnetList = optionalNetworkMap.get().getSubnetIdList();
    LOG.debug("{} getTargetDpnForPacketOut: Obtained subnetList as {} for network {}", LOGGING_PREFIX, subnetList, elanInfo.getName());
    for (Uuid subnetId : subnetList) {
        String vpnName = null;
        Subnetmap sn = VpnUtil.getSubnetmapFromItsUuid(broker, subnetId);
        if (sn != null && sn.getVpnId() != null) {
            vpnName = sn.getVpnId().getValue();
        }
        if (vpnName == null) {
            continue;
        }
        Optional<SubnetOpDataEntry> optionalSubs;
        optionalSubs = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, VpnUtil.buildSubnetOpDataEntryInstanceIdentifier(subnetId));
        if (!optionalSubs.isPresent()) {
            continue;
        }
        SubnetOpDataEntry subOpEntry = optionalSubs.get();
        if (subOpEntry.getNhDpnId() != null) {
            LOG.trace("{} getTargetDpnForPacketOut: Viewing Subnet {}", LOGGING_PREFIX, subnetId.getValue());
            boolean match = NWUtil.isIpInSubnet(ipAddress, subOpEntry.getSubnetCidr());
            LOG.trace("{} getTargetDpnForPacketOut: Viewing Subnet {} matching {}", LOGGING_PREFIX, subnetId.getValue(), match);
            if (match) {
                return subOpEntry;
            }
        }
    }
    return null;
}
Also used : ElanTagName(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) NetworkMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap)

Example 32 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class SubnetRoutePacketInHandler method handlePacketToInternalNetwork.

private void handlePacketToInternalNetwork(byte[] dstIp, String dstIpStr, int destinationAddress, long elanTag) throws UnknownHostException {
    SubnetOpDataEntry targetSubnetForPacketOut = getTargetSubnetForPacketOut(dataBroker, elanTag, destinationAddress);
    if (targetSubnetForPacketOut == null) {
        LOG.debug("Couldn't find matching subnet for elan tag {} and destination ip {}", elanTag, dstIpStr);
        VpnManagerCounters.subnet_route_packet_failed.inc();
        return;
    }
    Optional<Subnetmap> subnetMap = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnUtil.buildSubnetmapIdentifier(targetSubnetForPacketOut.getSubnetId()));
    if (!subnetMap.isPresent()) {
        LOG.debug("Couldn't find subnet map for subnet {}", targetSubnetForPacketOut.getSubnetId());
        VpnManagerCounters.subnet_route_packet_failed.inc();
        return;
    }
    String sourceIp = subnetMap.get().getRouterInterfaceFixedIp();
    if (sourceIp == null) {
        LOG.debug("Subnet map {} doesn't have a router interface ip defined", subnetMap.get().getId());
        VpnManagerCounters.subnet_route_packet_failed.inc();
        return;
    }
    String sourceMac = subnetMap.get().getRouterIntfMacAddress();
    if (sourceMac == null) {
        LOG.debug("Subnet map {} doesn't have a router interface mac address defined", subnetMap.get().getId());
        VpnManagerCounters.subnet_route_packet_failed.inc();
        return;
    }
    transmitArpPacket(targetSubnetForPacketOut.getNhDpnId(), sourceIp, sourceMac, dstIp, elanTag);
}
Also used : Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)

Example 33 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class SubnetmapChangeListener method update.

@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void update(InstanceIdentifier<Subnetmap> identifier, Subnetmap subnetmapOriginal, Subnetmap subnetmapUpdate) {
    LOG.debug("SubnetMapChangeListener update method - key {}, original {}, update {}", identifier, subnetmapOriginal, subnetmapUpdate);
    Uuid subnetId = subnetmapUpdate.getId();
    Network network = VpnUtil.getNeutronNetwork(dataBroker, subnetmapUpdate.getNetworkId());
    if (network == null) {
        LOG.error("SubnetMapChangeListener:update: network was not found for subnetId {}", subnetId.getValue());
        return;
    }
    if (VpnUtil.getIsExternal(network)) {
        LOG.debug("SubnetMapChangeListener:update: provider subnetwork {} is handling in " + "ExternalSubnetVpnInstanceListener", subnetId.getValue());
        return;
    }
    String elanInstanceName = subnetmapUpdate.getNetworkId().getValue();
    long elanTag = getElanTag(elanInstanceName);
    if (elanTag == 0L) {
        LOG.error("SubnetMapChangeListener:update: unable to fetch elantag from ElanInstance {} for subnetId {}", elanInstanceName, subnetId);
        return;
    }
    // update on BGPVPN or InternalVPN change
    Uuid vpnIdOld = subnetmapOriginal.getVpnId();
    Uuid vpnIdNew = subnetmapUpdate.getVpnId();
    if (!Objects.equals(vpnIdOld, vpnIdNew)) {
        LOG.info("SubnetMapChangeListener:update: update subnetOpDataEntry for subnet {} imported in VPN", subnetmapUpdate.getId().getValue());
        updateSubnetmapOpDataEntry(subnetmapOriginal.getVpnId(), subnetmapUpdate.getVpnId(), subnetmapUpdate, subnetmapOriginal, elanTag);
    }
    // update on Internet VPN Id change
    Uuid inetVpnIdOld = subnetmapOriginal.getInternetVpnId();
    Uuid inetVpnIdNew = subnetmapUpdate.getInternetVpnId();
    if (!Objects.equals(inetVpnIdOld, inetVpnIdNew)) {
        LOG.info("SubnetMapChangeListener:update: update subnetOpDataEntry for subnet {} imported in InternetVPN", subnetmapUpdate.getId().getValue());
        updateSubnetmapOpDataEntry(inetVpnIdOld, inetVpnIdNew, subnetmapUpdate, subnetmapOriginal, elanTag);
    }
    // update on PortList change
    List<Uuid> oldPortList;
    List<Uuid> newPortList;
    newPortList = subnetmapUpdate.getPortList() != null ? subnetmapUpdate.getPortList() : new ArrayList<>();
    oldPortList = subnetmapOriginal.getPortList() != null ? subnetmapOriginal.getPortList() : new ArrayList<>();
    if (newPortList.size() == oldPortList.size()) {
        return;
    }
    LOG.info("SubnetMapChangeListener:update: update port list for subnet {}", subnetmapUpdate.getId().getValue());
    if (newPortList.size() > oldPortList.size()) {
        for (Uuid portId : newPortList) {
            if (!oldPortList.contains(portId)) {
                vpnSubnetRouteHandler.onPortAddedToSubnet(subnetmapUpdate, portId);
                return;
            }
        }
    } else {
        for (Uuid portId : oldPortList) {
            if (!newPortList.contains(portId)) {
                vpnSubnetRouteHandler.onPortRemovedFromSubnet(subnetmapUpdate, portId);
                return;
            }
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) ArrayList(java.util.ArrayList)

Example 34 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap 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 35 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap 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)

Aggregations

Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)50 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)47 ArrayList (java.util.ArrayList)20 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)15 SubnetmapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey)12 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)11 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)10 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)9 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)9 SubnetOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)8 HashSet (java.util.HashSet)7 SubnetOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey)7 Subnetmaps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps)7 SubnetmapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)7 FixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 SubnetOpDataEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder)5 Router (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router)5 BigInteger (java.math.BigInteger)4 HashMap (java.util.HashMap)4