use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address in project netvirt by opendaylight.
the class VirtualPort method getIpv6Addresses.
@Override
public List<Ipv6Address> getIpv6Addresses() {
List<Ipv6Address> ipv6AddrList = snetInfo.values().stream().flatMap(subnetInfo -> Stream.of(subnetInfo.getIpAddr().getIpv6Address())).collect(Collectors.toList());
if (deviceOwner.equalsIgnoreCase(Ipv6Constants.NETWORK_ROUTER_INTERFACE)) {
Ipv6Address llAddr = Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(new MacAddress(macAddress));
ipv6AddrList.add(llAddr);
}
return ipv6AddrList;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address in project netvirt by opendaylight.
the class NeutronvpnUtils method getIpv6LinkLocalAddressFromMac.
protected static IpAddress getIpv6LinkLocalAddressFromMac(MacAddress mac) {
byte[] octets = bytesFromHexString(mac.getValue());
/* As per the RFC2373, steps involved to generate a LLA include
1. Convert the 48 bit MAC address to 64 bit value by inserting 0xFFFE
between OUI and NIC Specific part.
2. Invert the Universal/Local flag in the OUI portion of the address.
3. Use the prefix "FE80::/10" along with the above 64 bit Interface
identifier to generate the IPv6 LLA. */
StringBuffer interfaceID = new StringBuffer();
short u8byte = (short) (octets[0] & 0xff);
u8byte ^= 1 << 1;
interfaceID.append(Integer.toHexString(0xFF & u8byte));
interfaceID.append(StringUtils.leftPad(Integer.toHexString(0xFF & octets[1]), 2, "0"));
interfaceID.append(":");
interfaceID.append(Integer.toHexString(0xFF & octets[2]));
interfaceID.append("ff:fe");
interfaceID.append(StringUtils.leftPad(Integer.toHexString(0xFF & octets[3]), 2, "0"));
interfaceID.append(":");
interfaceID.append(Integer.toHexString(0xFF & octets[4]));
interfaceID.append(StringUtils.leftPad(Integer.toHexString(0xFF & octets[5]), 2, "0"));
Ipv6Address ipv6LLA = new Ipv6Address("fe80:0:0:0:" + interfaceID.toString());
IpAddress ipAddress = new IpAddress(ipv6LLA.getValue().toCharArray());
return ipAddress;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address in project openflowplugin by opendaylight.
the class MatchConvertorTest method testIpv6MatchConversion.
@Test
public void testIpv6MatchConversion() {
Ipv6MatchBuilder ipv6Builder = new Ipv6MatchBuilder();
ipv6Builder.setIpv6Source(new Ipv6Prefix("::1/128"));
ipv6Builder.setIpv6Destination(new Ipv6Prefix("::2/128"));
Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
ipv6LabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(3L));
ipv6Builder.setIpv6Label(ipv6LabelBuilder.build());
ipv6Builder.setIpv6NdTarget(new Ipv6Address("::4"));
ipv6Builder.setIpv6NdSll(new MacAddress("00:00:00:00:00:05"));
ipv6Builder.setIpv6NdTll(new MacAddress("00:00:00:00:00:06"));
Ipv6ExtHeaderBuilder extHdrBuilder = new Ipv6ExtHeaderBuilder();
extHdrBuilder.setIpv6Exthdr(153);
ipv6Builder.setIpv6ExtHeader(extHdrBuilder.build());
MatchBuilder builder = new MatchBuilder();
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", 7, entries.size());
MatchEntry entry = entries.get(0);
/* Due to conversion ambiguities, we always get "has mask" because
* an ip with no mask and prefix with /128 (or 32 in v4) cannot
* be distinguished */
checkEntryHeader(entry, Ipv6Src.class, true);
Assert.assertEquals("Wrong ipv6 src", "::1", ((Ipv6SrcCase) entry.getMatchEntryValue()).getIpv6Src().getIpv6Address().getValue());
entry = entries.get(1);
checkEntryHeader(entry, Ipv6Dst.class, true);
Assert.assertEquals("Wrong ipv6 dst", "::2", ((Ipv6DstCase) entry.getMatchEntryValue()).getIpv6Dst().getIpv6Address().getValue());
entry = entries.get(2);
checkEntryHeader(entry, Ipv6Flabel.class, false);
Assert.assertEquals("Wrong ipv6 flabel", 3, ((Ipv6FlabelCase) entry.getMatchEntryValue()).getIpv6Flabel().getIpv6Flabel().getValue().intValue());
entry = entries.get(3);
checkEntryHeader(entry, Ipv6NdTarget.class, false);
Assert.assertEquals("Wrong ipv6 nd target", "::4", ((Ipv6NdTargetCase) entry.getMatchEntryValue()).getIpv6NdTarget().getIpv6Address().getValue());
entry = entries.get(4);
checkEntryHeader(entry, Ipv6NdSll.class, false);
Assert.assertEquals("Wrong ipv6 nd sll", "00:00:00:00:00:05", ((Ipv6NdSllCase) entry.getMatchEntryValue()).getIpv6NdSll().getMacAddress().getValue());
entry = entries.get(5);
checkEntryHeader(entry, Ipv6NdTll.class, false);
Assert.assertEquals("Wrong ipv6 nd tll", "00:00:00:00:00:06", ((Ipv6NdTllCase) entry.getMatchEntryValue()).getIpv6NdTll().getMacAddress().getValue());
entry = entries.get(6);
checkEntryHeader(entry, Ipv6Exthdr.class, false);
Assert.assertEquals("Wrong ipv6 ext hdr", new Ipv6ExthdrFlags(false, true, false, true, false, true, false, true, false), ((Ipv6ExthdrCase) entry.getMatchEntryValue()).getIpv6Exthdr().getPseudoField());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address in project openflowplugin by opendaylight.
the class OF13MatchSerializerTest method testIpv6Incorrect.
/**
* Test for correct serialization of incorrect Ipv6Address match entry.
*/
@Test(expected = IllegalArgumentException.class)
public void testIpv6Incorrect() {
MatchBuilder builder = new MatchBuilder();
builder.setType(OxmMatchType.class);
final List<MatchEntry> entries = new ArrayList<>();
// ipv6 match entry with incorrect Ipv6 address
MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv6Src.class);
entriesBuilder.setHasMask(false);
Ipv6SrcCaseBuilder ipv6SrcCaseBuilder = new Ipv6SrcCaseBuilder();
Ipv6SrcBuilder ipv6SrcBuilder = new Ipv6SrcBuilder();
ipv6SrcBuilder.setIpv6Address(new Ipv6Address("1:2::::8"));
ipv6SrcCaseBuilder.setIpv6Src(ipv6SrcBuilder.build());
entriesBuilder.setMatchEntryValue(ipv6SrcCaseBuilder.build());
entries.add(entriesBuilder.build());
builder.setMatchEntry(entries);
Match match = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
matchSerializer.serialize(match, out);
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address in project openflowplugin by opendaylight.
the class OF13MatchSerializerTest method testIpv6Various.
/**
* Test for correct serialization of Ipv6Address match entry.
*/
@Test
public void testIpv6Various() {
MatchBuilder builder = new MatchBuilder();
builder.setType(OxmMatchType.class);
final List<MatchEntry> entries = new ArrayList<>();
// ipv6 match entry with correct Ipv6 address
MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv6Src.class);
entriesBuilder.setHasMask(false);
Ipv6SrcCaseBuilder ipv6SrcCaseBuilder = new Ipv6SrcCaseBuilder();
Ipv6SrcBuilder ipv6SrcBuilder = new Ipv6SrcBuilder();
ipv6SrcBuilder.setIpv6Address(new Ipv6Address("1:2:3:4:5:6:7:8"));
ipv6SrcCaseBuilder.setIpv6Src(ipv6SrcBuilder.build());
entriesBuilder.setMatchEntryValue(ipv6SrcCaseBuilder.build());
entries.add(entriesBuilder.build());
// ipv6 match entry with abbreviated Ipv6 address
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
entriesBuilder.setHasMask(false);
Ipv6NdTargetCaseBuilder ipv6NdTargetCaseBuilder = new Ipv6NdTargetCaseBuilder();
Ipv6NdTargetBuilder ipv6NdTargetBuilder = new Ipv6NdTargetBuilder();
ipv6NdTargetBuilder.setIpv6Address(new Ipv6Address("1:2::6:7:8"));
ipv6NdTargetCaseBuilder.setIpv6NdTarget(ipv6NdTargetBuilder.build());
entriesBuilder.setMatchEntryValue(ipv6NdTargetCaseBuilder.build());
entries.add(entriesBuilder.build());
// ipv6 match entry with abbreviated Ipv6 address
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv6Dst.class);
entriesBuilder.setHasMask(false);
Ipv6DstCaseBuilder ipv6DstCaseBuilder = new Ipv6DstCaseBuilder();
Ipv6DstBuilder ipv6DstBuilder = new Ipv6DstBuilder();
ipv6DstBuilder.setIpv6Address(new Ipv6Address("1::8"));
ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build());
entriesBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build());
entries.add(entriesBuilder.build());
// ipv6 match entry with abbreviated Ipv6 address
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv6Dst.class);
entriesBuilder.setHasMask(false);
ipv6DstCaseBuilder = new Ipv6DstCaseBuilder();
ipv6DstBuilder = new Ipv6DstBuilder();
ipv6DstBuilder.setIpv6Address(new Ipv6Address("::1"));
ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build());
entriesBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build());
entries.add(entriesBuilder.build());
// ipv6 match entry with abbreviated Ipv6 address
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv6Dst.class);
entriesBuilder.setHasMask(false);
ipv6DstCaseBuilder = new Ipv6DstCaseBuilder();
ipv6DstBuilder = new Ipv6DstBuilder();
ipv6DstBuilder.setIpv6Address(new Ipv6Address("::"));
ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build());
entriesBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build());
entries.add(entriesBuilder.build());
builder.setMatchEntry(entries);
Match match = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
matchSerializer.serialize(match, out);
Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
Assert.assertEquals("Wrong field and mask", 52, out.readUnsignedByte());
Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 3, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 4, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 5, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort());
Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
Assert.assertEquals("Wrong field and mask", 62, out.readUnsignedByte());
Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort());
Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte());
Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort());
Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte());
Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte());
Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
}
Aggregations