use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project bgpcep by opendaylight.
the class LinkstateAttributeParserTest method testPositiveV4Prefixes.
@Test
public void testPositiveV4Prefixes() throws BGPParsingException {
final AttributesBuilder builder = createUnreachBuilder(new PrefixCaseBuilder().setPrefixDescriptors(new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32"))).build()).build());
this.parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder);
final Attributes1 attrs = builder.getAugmentation(Attributes1.class);
final PrefixAttributes ls = ((PrefixAttributesCase) attrs.getLinkStateAttribute()).getPrefixAttributes();
assertNotNull(ls);
assertNotNull(ls.getSrRange());
assertFalse(ls.getSrRange().isInterArea());
assertEquals(1, ls.getSrRange().getSubTlvs().size());
assertNotNull(ls.getSrBindingSidLabels());
final IgpBits ispBits = ls.getIgpBits();
assertTrue(ispBits.getUpDown().isUpDown());
assertTrue(ispBits.isIsIsUpDown());
assertTrue(ispBits.isOspfNoUnicast());
assertTrue(ispBits.isOspfLocalAddress());
assertTrue(ispBits.isOspfPropagateNssa());
assertEquals(2, ls.getRouteTags().size());
assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }, ls.getRouteTags().get(0).getValue());
assertEquals(1, ls.getExtendedTags().size());
assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30, (byte) 0x50, (byte) 0x70 }, ls.getExtendedTags().get(0).getValue());
assertEquals(10, ls.getPrefixMetric().getValue().intValue());
assertEquals("10.25.2.27", ls.getOspfForwardingAddress().getIpv4Address().getValue());
// serialization
final ByteBuf buff = Unpooled.buffer();
this.parser.serializeAttribute(builder.build(), buff);
buff.skipBytes(3);
// there is unresolved TLV at the end, that needs to be cut off
assertArrayEquals(P4_ATTR, ByteArray.getAllBytes(buff));
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project bgpcep by opendaylight.
the class LinkstateTopologyBuilder method createPrefix.
private void createPrefix(final WriteTransaction trans, final UriBuilder base, final LinkstateRoute value, final PrefixCase prefixCase, final Attributes attributes) {
final IpPrefix ippfx = prefixCase.getPrefixDescriptors().getIpReachabilityInformation();
if (ippfx == null) {
LOG.warn("IP reachability not present in prefix {} route {}, skipping it", prefixCase, value);
return;
}
final PrefixBuilder pb = new PrefixBuilder();
final PrefixKey pk = new PrefixKey(ippfx);
pb.setKey(pk);
pb.setPrefix(ippfx);
final PrefixAttributes pa;
// Very defensive lookup
final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
if (attr != null) {
final LinkStateAttribute attrType = attr.getLinkStateAttribute();
if (attrType != null) {
pa = ((PrefixAttributesCase) attrType).getPrefixAttributes();
} else {
LOG.debug("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
pa = null;
}
} else {
LOG.debug("Missing attributes in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
pa = null;
}
if (pa != null) {
pb.setMetric(pa.getPrefixMetric().getValue());
}
ProtocolUtil.augmentProtocolId(value, pa, pb);
final Prefix pfx = pb.build();
LOG.debug("Created prefix {} for {}", pfx, prefixCase);
/*
* All set, but... the hosting node may not exist, we may need to fake it.
*/
final NodeId node = buildNodeId(base, prefixCase.getAdvertisingNodeDescriptors());
NodeHolder nh = this.nodes.get(node);
if (nh == null) {
nh = getNode(node);
nh.addPrefix(pfx);
putNode(trans, nh);
} else {
nh.addPrefix(pfx);
final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
trans.put(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk), pfx);
}
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project bgpcep by opendaylight.
the class LinkstateTopologyBuilder method removePrefix.
private void removePrefix(final WriteTransaction trans, final UriBuilder base, final PrefixCase prefixCase) {
final NodeId node = buildNodeId(base, prefixCase.getAdvertisingNodeDescriptors());
final NodeHolder nh = this.nodes.get(node);
if (nh != null) {
LOG.debug("Removed prefix {}", prefixCase);
final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
final IpPrefix ippfx = prefixCase.getPrefixDescriptors().getIpReachabilityInformation();
if (ippfx == null) {
LOG.warn("IP reachability not present in prefix {}, skipping it", prefixCase);
return;
}
final PrefixKey pk = new PrefixKey(ippfx);
trans.delete(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk));
nh.removePrefix(prefixCase);
checkNodeForRemoval(trans, nh);
} else {
LOG.warn("Removing prefix from non-existing node {}", node);
}
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project bgpcep by opendaylight.
the class PCEPRROSubobjectParserTest method testRROIp4PrefixSubobject.
@Test
public void testRROIp4PrefixSubobject() throws PCEPDeserializerException {
final RROIpv4PrefixSubobjectParser parser = new RROIpv4PrefixSubobjectParser();
final SubobjectBuilder subs = new SubobjectBuilder();
subs.setProtectionAvailable(true);
subs.setProtectionInUse(false);
subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build()).build());
assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip4PrefixBytes, 2))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeSubobject(subs.build(), buff);
assertArrayEquals(ip4PrefixBytes, ByteArray.getAllBytes(buff));
try {
parser.parseSubobject(null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project bgpcep by opendaylight.
the class PCEPRROSubobjectParserTest method testRROIp6PrefixSubobject.
@Test
public void testRROIp6PrefixSubobject() throws PCEPDeserializerException {
final RROIpv6PrefixSubobjectParser parser = new RROIpv6PrefixSubobjectParser();
final SubobjectBuilder subs = new SubobjectBuilder();
subs.setProtectionAvailable(false);
subs.setProtectionInUse(true);
subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build()).build());
assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip6PrefixBytes, 2))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeSubobject(subs.build(), buff);
assertArrayEquals(ip6PrefixBytes, ByteArray.getAllBytes(buff));
try {
parser.parseSubobject(null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
}
Aggregations