Search in sources :

Example 26 with Ipv6Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project openflowplugin by opendaylight.

the class IpConversionUtil method extractIpv6AddressMask.

@Nullable
public static Ipv6ArbitraryMask extractIpv6AddressMask(final Ipv6Prefix ipv6Prefix) {
    Iterator<String> addressParts = PREFIX_SPLITTER.split(ipv6Prefix.getValue()).iterator();
    addressParts.next();
    int maskLength = 0;
    if (addressParts.hasNext()) {
        maskLength = Integer.parseInt(addressParts.next());
    }
    BitSet ipmask = new BitSet(128);
    ipmask.set(0, maskLength, true);
    ipmask.set(maskLength + 1, 128, false);
    byte[] finalmask = new byte[16];
    System.arraycopy(ipmask.toByteArray(), 0, finalmask, 0, ipmask.toByteArray().length);
    InetAddress inetAddress = null;
    try {
        inetAddress = InetAddress.getByAddress(finalmask);
    } catch (UnknownHostException e) {
        LOG.error("Failed to convert the Ipv6 subnetmask from integer to mask value ", e);
        return null;
    }
    return new Ipv6ArbitraryMask(inetAddress.getHostAddress());
}
Also used : UnknownHostException(java.net.UnknownHostException) Ipv6ArbitraryMask(org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask) BitSet(java.util.BitSet) InetAddress(java.net.InetAddress) Nullable(javax.annotation.Nullable)

Example 27 with Ipv6Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project openflowplugin by opendaylight.

the class MatchConvertorTest method testIpv6MatchConversionWithMasks.

@Test
public void testIpv6MatchConversionWithMasks() {
    MatchBuilder builder = new MatchBuilder();
    Ipv6MatchBuilder ipv6Builder = new Ipv6MatchBuilder();
    ipv6Builder.setIpv6Source(new Ipv6Prefix("::/24"));
    ipv6Builder.setIpv6Destination(new Ipv6Prefix("::/64"));
    builder.setLayer3Match(ipv6Builder.build());
    Match match = builder.build();
    Optional<List<MatchEntry>> entriesOptional = converterManager.convert(match, new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
    List<MatchEntry> entries = entriesOptional.get();
    Assert.assertEquals("Wrong entries size", 2, entries.size());
    MatchEntry entry = entries.get(0);
    checkEntryHeader(entry, Ipv6Src.class, true);
    Assert.assertEquals("Wrong ipv6 src", "::", ((Ipv6SrcCase) entry.getMatchEntryValue()).getIpv6Src().getIpv6Address().getValue());
    Assert.assertArrayEquals("Wrong ipv6 src mask", new byte[] { (byte) 255, (byte) 255, (byte) 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, ((Ipv6SrcCase) entry.getMatchEntryValue()).getIpv6Src().getMask());
    entry = entries.get(1);
    checkEntryHeader(entry, Ipv6Dst.class, true);
    Assert.assertEquals("Wrong ipv6 dst", "::", ((Ipv6DstCase) entry.getMatchEntryValue()).getIpv6Dst().getIpv6Address().getValue());
    Assert.assertArrayEquals("Wrong ipv6 src mask", new byte[] { (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, 0, 0, 0, 0, 0, 0, 0, 0 }, ((Ipv6DstCase) entry.getMatchEntryValue()).getIpv6Dst().getMask());
}
Also used : VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) Ipv6DstCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6DstCase) List(java.util.List) ArpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder) Icmpv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder) TunnelIpv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder) Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) Ipv6MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder) IpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder) Icmpv6MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder) SctpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder) UdpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder) TcpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Ipv6MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder) Ipv6SrcCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6SrcCase) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match) Test(org.junit.Test)

Example 28 with Ipv6Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project lispflowmapping by opendaylight.

the class MaskUtilTest method normalizeTest_withIpv6Prefix.

/**
 * Tests {@link MaskUtil#normalize} method with Ipv6Prefix.
 */
@Test
public void normalizeTest_withIpv6Prefix() {
    // input ip: 1111:2222:3333:4444:5555:6666:7777:8888, mask: 66
    final Eid result = MaskUtil.normalize(EID_IPV6_PREFIX);
    final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix resultPrefix = (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix) result.getAddress();
    // expected result
    final String expectedResult = "1111:2222:3333:4444:4000::" + MASK_3;
    assertEquals(expectedResult, resultPrefix.getIpv6Prefix().getValue());
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix) Test(org.junit.Test)

Example 29 with Ipv6Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project lispflowmapping by opendaylight.

the class LispAddressUtil method toEid.

public static Eid toEid(Ipv6Prefix prefix, InstanceIdType vni) {
    EidBuilder builder = new EidBuilder();
    builder.setAddressType(Ipv6PrefixAfi.class);
    builder.setVirtualNetworkId(vni);
    builder.setAddress((Address) new Ipv6PrefixBuilder().setIpv6Prefix(prefix).build());
    return builder.build();
}
Also used : Ipv6PrefixBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6PrefixBuilder) EidBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder)

Example 30 with Ipv6Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project lispflowmapping by opendaylight.

the class MaskUtil method normalize.

public static Eid normalize(Eid eid, short mask) {
    Address address = eid.getAddress();
    try {
        if (address instanceof Ipv4PrefixBinary) {
            byte[] addr = ((Ipv4PrefixBinary) address).getIpv4AddressBinary().getValue();
            return LispAddressUtil.asIpv4PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
        } else if (address instanceof Ipv6PrefixBinary) {
            byte[] addr = ((Ipv6PrefixBinary) address).getIpv6AddressBinary().getValue();
            return LispAddressUtil.asIpv6PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
        } else if (address instanceof Ipv4Prefix) {
            final String addr = getPrefixAddress(((Ipv4Prefix) address).getIpv4Prefix().getValue());
            InetAddress normalized = normalizeIP(InetAddresses.forString(addr), mask);
            return LispAddressUtil.asIpv4PrefixEid(eid, (Inet4Address) normalized, mask);
        } else if (address instanceof Ipv6Prefix) {
            final String addr = getPrefixAddress(((Ipv6Prefix) address).getIpv6Prefix().getValue());
            InetAddress normalized = normalizeIP(InetAddresses.forString(addr), mask);
            return LispAddressUtil.asIpv6PrefixEid(eid, (Inet6Address) normalized, mask);
        } else if (address instanceof InstanceId) {
            // TODO - not absolutely necessary, but should be implemented
            return eid;
        }
    } catch (UnknownHostException e) {
        LOG.warn("Failed to normalize EID {} with mask {}, returning original EID", eid, mask, e);
    }
    return eid;
}
Also used : Ipv4PrefixBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary) InetAddress(java.net.InetAddress) Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address) Inet4Address(java.net.Inet4Address) Inet6Address(java.net.Inet6Address) SimpleAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress) UnknownHostException(java.net.UnknownHostException) InstanceId(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId) Ipv6PrefixBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary) Inet6Address(java.net.Inet6Address) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix) InetAddress(java.net.InetAddress) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix)

Aggregations

Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)63 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)20 ByteBuf (io.netty.buffer.ByteBuf)16 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)13 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)13 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)12 Ipv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder)11 Ipv6Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address)10 Flowspec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.Flowspec)8 FlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.FlowspecBuilder)8 InetAddress (java.net.InetAddress)6 AceIpv6Builder (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.AceIpv6Builder)6 SourceIpv6PrefixCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.group.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCaseBuilder)6 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)6 Attributes1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1Builder)6 MpReachNlriBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder)6 AdvertizedRoutesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder)6 IpPrefixSubobject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject)6 SimpleAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress)5