use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix in project bgpcep by opendaylight.
the class GenericConditionPolicyHandler method createPrefixes.
private static List<IpPrefix> createPrefixes(final Prefix prefixContainer) {
final IpPrefix prefix = prefixContainer.getIpPrefix();
if (prefixContainer.getMasklengthRange().equals(EXACT)) {
return Collections.singletonList(prefix);
}
final String[] range = prefixContainer.getMasklengthRange().split("\\..");
boolean ipv4 = false;
final String prefixString;
if (prefix.getIpv4Prefix() != null) {
prefixString = prefix.getIpv4Prefix().getValue();
ipv4 = true;
} else {
prefixString = prefix.getIpv6Prefix().getValue();
}
int from = Integer.parseInt(range[0]);
final List<IpPrefix> prefixes = new ArrayList<>();
while (from <= Integer.parseInt(range[1])) {
final String prefixVal = StringUtils.replacePattern(prefixString, "[/][0-9]+", "/" + Integer.toString(from));
if (ipv4) {
prefixes.add(new IpPrefix(new Ipv4Prefix(prefixVal)));
} else {
prefixes.add(new IpPrefix(new Ipv6Prefix(prefixVal)));
}
from++;
}
return prefixes;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix in project bgpcep by opendaylight.
the class Ipv6ReachabilityTopologyBuilderTest method setUp.
@Before
@Override
public void setUp() {
super.setUp();
this.ipv6TopoBuilder = new Ipv6ReachabilityTopologyBuilder(getDataBroker(), LOC_RIB_REF, TEST_TOPOLOGY_ID);
this.ipv6TopoBuilder.start();
final InstanceIdentifier<Tables> path = LOC_RIB_REF.getInstanceIdentifier().builder().child(LocRib.class).child(Tables.class, new TablesKey(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class)).build();
this.ipv6RouteIID = path.builder().child((Class) Ipv6Routes.class).child(Ipv6Route.class, new Ipv6RouteKey(new PathId(PATH_ID), new Ipv6Prefix(ROUTE_IP6PREFIX))).build();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix in project bgpcep by opendaylight.
the class IPAddressesAndPrefixesTest method testPrefixForByteBuf.
@Test
public void testPrefixForByteBuf() {
final ByteBuf bb = Unpooled.wrappedBuffer(new byte[] { 0x0e, 123, 122, 0x40, 0x20, (byte) 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x80, 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, (byte) 0x88, (byte) 0x89 });
assertEquals(new Ipv4Prefix("123.122.0.0/14"), Ipv4Util.prefixForByteBuf(bb));
assertEquals(new Ipv6Prefix("2001::/64"), Ipv6Util.prefixForByteBuf(bb));
assertEquals(new Ipv4Prefix("0.0.0.0/0"), Ipv4Util.prefixForByteBuf(bb));
assertEquals(new Ipv6Prefix("::/0"), Ipv6Util.prefixForByteBuf(bb));
// test prefix length 128, as its signed byte value is -128
assertEquals(new Ipv6Prefix("2001:4860:4860:1:20::8889/128"), Ipv6Util.prefixForByteBuf(bb));
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix in project bgpcep by opendaylight.
the class IPAddressesAndPrefixesTest method testBytesForPrefix6Begin.
@Test
public void testBytesForPrefix6Begin() {
byte[] bytes = new byte[] { 0x20, 0x01, 0x0d, (byte) 0xb8, 0x00, 0x01, 0x00, 0x02 };
assertEquals(new Ipv6Prefix("2001:db8:1:2::/64"), Ipv6Util.prefixForBytes(bytes, 64));
bytes = new byte[] { (byte) 0 };
assertEquals(new Ipv6Prefix("::/0"), Ipv6Util.prefixForBytes(bytes, 0));
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix in project bgpcep by opendaylight.
the class EROIpv6PrefixSubobjectParser method serializeSubobject.
@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
final IpPrefix prefix = specObj.getIpPrefix();
final ByteBuf body = Unpooled.buffer();
Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
writeIpv6Prefix(prefix.getIpv6Prefix(), body);
body.writeZero(RESERVED);
EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
}
Aggregations