Search in sources :

Example 21 with Ipv6

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv6._case.Ipv6 in project netvirt by opendaylight.

the class ExternalRoutersListener method subnetRegisterMapping.

protected void subnetRegisterMapping(Routers routerEntry, Uint32 segmentId) {
    LOG.debug("subnetRegisterMapping : Fetching values from extRouters model");
    List<String> externalIps = NatUtil.getIpsListFromExternalIps(new ArrayList<ExternalIps>(routerEntry.nonnullExternalIps().values()));
    int counter = 0;
    int extIpCounter = externalIps.size();
    LOG.debug("subnetRegisterMapping : counter values before looping counter {} and extIpCounter {}", counter, extIpCounter);
    @Nullable List<Uuid> subnetIds = routerEntry.getSubnetIds();
    if (subnetIds == null) {
        return;
    }
    for (Uuid subnet : subnetIds) {
        LOG.debug("subnetRegisterMapping : Looping internal subnets for subnet {}", subnet);
        InstanceIdentifier<Subnetmap> subnetmapId = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnet)).build();
        Optional<Subnetmap> sn;
        try {
            sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetmapId);
        } catch (InterruptedException | ExecutionException e) {
            LOG.error("Failed to read SubnetMap for  subnetmap Id {}", subnetmapId, e);
            sn = Optional.empty();
        }
        if (sn.isPresent()) {
            // subnets
            Subnetmap subnetmapEntry = sn.get();
            String subnetString = subnetmapEntry.getSubnetIp();
            String[] subnetSplit = subnetString.split("/");
            String subnetIp = subnetSplit[0];
            try {
                InetAddress address = InetAddress.getByName(subnetIp);
                if (address instanceof Inet6Address) {
                    LOG.debug("subnetRegisterMapping : Skipping ipv6 subnet {} for the router {} with ipv6 address " + "{} ", subnet, routerEntry.getRouterName(), address);
                    continue;
                }
            } catch (UnknownHostException e) {
                LOG.error("subnetRegisterMapping : Invalid ip address {}", subnetIp, e);
                return;
            }
            String subnetPrefix = "0";
            if (subnetSplit.length == 2) {
                subnetPrefix = subnetSplit[1];
            }
            IPAddress subnetAddr = new IPAddress(subnetIp, Integer.parseInt(subnetPrefix));
            LOG.debug("subnetRegisterMapping : subnetAddr is {} and subnetPrefix is {}", subnetAddr.getIpAddress(), subnetAddr.getPrefixLength());
            // externalIps
            LOG.debug("subnetRegisterMapping : counter values counter {} and extIpCounter {}", counter, extIpCounter);
            if (extIpCounter != 0) {
                if (counter < extIpCounter) {
                    String[] ipSplit = externalIps.get(counter).split("/");
                    String externalIp = ipSplit[0];
                    String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
                    if (ipSplit.length == 2) {
                        extPrefix = ipSplit[1];
                    }
                    IPAddress externalIpAddr = new IPAddress(externalIp, Integer.parseInt(extPrefix));
                    LOG.debug("subnetRegisterMapping : externalIp is {} and extPrefix  is {}", externalIpAddr.getIpAddress(), externalIpAddr.getPrefixLength());
                    naptManager.registerMapping(segmentId, subnetAddr, externalIpAddr);
                    LOG.debug("subnetRegisterMapping : Called registerMapping for subnetIp {}, prefix {}, " + "externalIp {}. prefix {}", subnetIp, subnetPrefix, externalIp, extPrefix);
                } else {
                    // Reset the counter which runs on externalIps for round-robbin effect
                    counter = 0;
                    LOG.debug("subnetRegisterMapping : Counter on externalIps got reset");
                    String[] ipSplit = externalIps.get(counter).split("/");
                    String externalIp = ipSplit[0];
                    String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
                    if (ipSplit.length == 2) {
                        extPrefix = ipSplit[1];
                    }
                    IPAddress externalIpAddr = new IPAddress(externalIp, Integer.parseInt(extPrefix));
                    LOG.debug("subnetRegisterMapping : externalIp is {} and extPrefix  is {}", externalIpAddr.getIpAddress(), externalIpAddr.getPrefixLength());
                    naptManager.registerMapping(segmentId, subnetAddr, externalIpAddr);
                    LOG.debug("subnetRegisterMapping : Called registerMapping for subnetIp {}, prefix {}, " + "externalIp {}. prefix {}", subnetIp, subnetPrefix, externalIp, extPrefix);
                }
            }
            counter++;
            LOG.debug("subnetRegisterMapping : Counter on externalIps incremented to {}", counter);
        } else {
            LOG.warn("subnetRegisterMapping : No internal subnets present in extRouters Model");
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Inet6Address(java.net.Inet6Address) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) ExecutionException(java.util.concurrent.ExecutionException) InetAddress(java.net.InetAddress) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 22 with Ipv6

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv6._case.Ipv6 in project netvirt by opendaylight.

the class SubnetGwMacChangeListener method handleSubnetGwIpChange.

private void handleSubnetGwIpChange(LearntVpnVipToPort learntVpnVipToPort) {
    String macAddress = learntVpnVipToPort.getMacAddress();
    if (macAddress == null) {
        LOG.error("handleSubnetGwIpChange : Mac address is null for LearntVpnVipToPort for vpn {} prefix {}", learntVpnVipToPort.getVpnName(), learntVpnVipToPort.getPortFixedip());
        return;
    }
    String fixedIp = learntVpnVipToPort.getPortFixedip();
    if (fixedIp == null) {
        LOG.error("handleSubnetGwIpChange : Fixed ip is null for LearntVpnVipToPort for vpn {}", learntVpnVipToPort.getVpnName());
        return;
    }
    try {
        InetAddress address = InetAddress.getByName(fixedIp);
        if (address instanceof Inet6Address) {
            // TODO: Revisit when IPv6 North-South communication support is added.
            LOG.debug("handleSubnetGwIpChange : Skipping ipv6 address {}.", address);
            return;
        }
    } catch (UnknownHostException e) {
        LOG.warn("handleSubnetGwIpChange : Invalid ip address {}", fixedIp, e);
        return;
    }
    for (Uuid subnetId : nvpnManager.getSubnetIdsForGatewayIp(new IpAddress(new Ipv4Address(fixedIp)))) {
        LOG.trace("handleSubnetGwIpChange : Updating MAC resolution on vpn {} for GW ip {} to {}", learntVpnVipToPort.getVpnName(), fixedIp, macAddress);
        extNetworkInstaller.installExtNetGroupEntries(subnetId, macAddress);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) UnknownHostException(java.net.UnknownHostException) Inet6Address(java.net.Inet6Address) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) InetAddress(java.net.InetAddress) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 23 with Ipv6

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv6._case.Ipv6 in project netvirt by opendaylight.

the class NeutronvpnUtils method getIpVersionChoicesFromRouterUuid.

/**
 * Method to get an ipVersionChosen as IPV4 and/or IPV6 or undefined from the subnetmaps of the router.
 * @param routerUuid the Uuid for which find out the IP version associated
 * @return an IpVersionChoice used by the router from its attached subnetmaps. IpVersionChoice.UNDEFINED if any
 */
public IpVersionChoice getIpVersionChoicesFromRouterUuid(Uuid routerUuid) {
    IpVersionChoice rep = IpVersionChoice.UNDEFINED;
    if (routerUuid == null) {
        return rep;
    }
    List<Subnetmap> subnetmapList = getNeutronRouterSubnetMaps(routerUuid);
    if (subnetmapList.isEmpty()) {
        return rep;
    }
    for (Subnetmap sn : subnetmapList) {
        if (sn.getSubnetIp() != null) {
            IpVersionChoice ipVers = getIpVersionFromString(sn.getSubnetIp());
            if (rep.choice != ipVers.choice) {
                rep = rep.addVersion(ipVers);
            }
            if (rep.choice == IpVersionChoice.IPV4AND6.choice) {
                return rep;
            }
        }
    }
    return rep;
}
Also used : Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Example 24 with Ipv6

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv6._case.Ipv6 in project netvirt by opendaylight.

the class QosNeutronUtils method setPortDscpMarking.

public void setPortDscpMarking(Port port, DscpmarkingRules dscpMark) {
    Uint64 dpnId = getDpnForInterface(port.getUuid().getValue());
    String ifName = port.getUuid().getValue();
    if (dpnId.equals(Uint64.ZERO)) {
        LOG.info("DPN ID for interface {} not found. Cannot set dscp value {} on port {}", port.getUuid().getValue(), dscpMark, port.getUuid().getValue());
        return;
    }
    if (!qosEosHandler.isQosClusterOwner()) {
        qosServiceConfiguredPorts.add(port.getUuid());
        LOG.trace("Not Qos Cluster Owner. Ignoring setting DSCP marking");
        return;
    } else {
        Interface ifState = getInterfaceStateFromOperDS(ifName);
        Short dscpValue = dscpMark.getDscpMark().toJava();
        int ipVersions = getIpVersions(port);
        // 1. OF rules
        if (hasIpv4Addr(ipVersions)) {
            LOG.trace("setting ipv4 flow for port: {}, dscp: {}", ifName, dscpValue);
            addFlow(dpnId, dscpValue, ifName, NwConstants.ETHTYPE_IPV4, ifState);
        }
        if (hasIpv6Addr(ipVersions)) {
            LOG.trace("setting ipv6 flow for port: {}, dscp: {}", ifName, dscpValue);
            addFlow(dpnId, dscpValue, ifName, NwConstants.ETHTYPE_IPV6, ifState);
        }
        if (qosServiceConfiguredPorts.add(port.getUuid())) {
            // bind qos service to interface
            bindservice(ifName);
        }
    }
}
Also used : Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 25 with Ipv6

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv6._case.Ipv6 in project netvirt by opendaylight.

the class DisplayAclDataCaches method printAcl.

private void printAcl(String aclId, Acl acl) {
    session.getConsole().println();
    session.getConsole().println(ACL_HEADER + String.format("%-32s  ", aclId));
    if (null != acl.getAccessListEntries() && null != acl.getAccessListEntries().getAce()) {
        printHeader(ACL_ENTRIES_HEADERS, ACL_ENTRIES_HEADER_LINE);
        List<Ace> aceList = acl.getAccessListEntries().getAce();
        for (Ace ace : aceList) {
            LOG.info("ace data: {}", ace);
            SecurityRuleAttr aceAttr = getAccessListAttributes(ace);
            Class<? extends DirectionBase> aceAttrDirection = aceAttr.getDirection();
            AceIp aceIp = (AceIp) ace.getMatches().getAceType();
            AceIpVersion ipVersion = aceIp.getAceIpVersion();
            Uint8 protoNum = aceIp.getProtocol();
            String protocol = "Any";
            if (null != protoNum) {
                protocol = protoMap.get(protoNum.toString());
                protocol = (protocol == null) ? protoNum.toString() : protocol;
            }
            String ipVer = "";
            String direction = DirectionEgress.class.equals(aceAttrDirection) ? "Egress" : "Ingress";
            String ipPrefix = " -- ";
            if (null != ipVersion && ipVersion instanceof AceIpv4) {
                ipVer = "IPv4";
                Ipv4Prefix srcNetwork = ((AceIpv4) ipVersion).getSourceIpv4Network();
                if (null != srcNetwork) {
                    ipPrefix = srcNetwork.getValue();
                }
            } else if (null != ipVersion && ipVersion instanceof AceIpv6) {
                ipVer = "IPv6";
                Ipv6Prefix srcNetwork = ((AceIpv6) ipVersion).getSourceIpv6Network();
                if (null != srcNetwork) {
                    ipPrefix = srcNetwork.getValue();
                }
            }
            String remoteGroupId = "-";
            if (aceAttr.getRemoteGroupId() != null) {
                remoteGroupId = aceAttr.getRemoteGroupId().getValue();
                ipPrefix = "-";
            }
            String prefixAndRemoteId = ipPrefix + " / " + remoteGroupId;
            session.getConsole().print(String.format(ACE_ENTRIES_FORMAT_STRING, ace.key().getRuleName(), direction, protocol, ipVer, prefixAndRemoteId));
        }
    }
    session.getConsole().println();
}
Also used : Uint8(org.opendaylight.yangtools.yang.common.Uint8) Ace(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace) AceIp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIp) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix) SecurityRuleAttr(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.SecurityRuleAttr) AceIpVersion(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.AceIpVersion) DirectionEgress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionEgress) AceIpv6(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv6) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) AceIpv4(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4)

Aggregations

Test (org.junit.Test)71 ArrayList (java.util.ArrayList)44 Ipv6Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address)38 ByteBuf (io.netty.buffer.ByteBuf)27 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)24 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)21 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)20 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)19 InetAddress (java.net.InetAddress)17 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)17 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)16 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)13 List (java.util.List)12 Inet6Address (java.net.Inet6Address)10 UnknownHostException (java.net.UnknownHostException)10 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)10 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)10 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)10 SimpleAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress)9 Ipv6AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone)8