use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.ProtocolId in project bgpcep by opendaylight.
the class RangeTlvParser method parseRangeSubTlvs.
private static List<SubTlvs> parseRangeSubTlvs(final ByteBuf buffer, final ProtocolId protocolId) {
final List<SubTlvs> subTlvs = new ArrayList<>();
while (buffer.isReadable()) {
final RangeSubTlv subTlvCase;
final int type = buffer.readUnsignedShort();
final int length = buffer.readUnsignedShort();
switch(type) {
case PREFIX_SID:
subTlvCase = new PrefixSidTlvCaseBuilder().setPrefixSidTlv(new PrefixSidTlvBuilder(SrPrefixAttributesParser.parseSrPrefix(buffer.readSlice(length), protocolId)).build()).build();
break;
case IPV6_PREFIX_SID:
subTlvCase = new Ipv6PrefixSidTlvCaseBuilder().setIpv6PrefixSidTlv(new Ipv6PrefixSidTlvBuilder(Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(buffer.readSlice(length))).build()).build();
break;
case BINDING_SID:
subTlvCase = new BindingSidTlvCaseBuilder(BindingSidLabelParser.parseBindingSidLabel(buffer.readSlice(length), protocolId)).build();
break;
case SID_TYPE:
subTlvCase = new SidLabelTlvCaseBuilder().setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndex(Size.forValue(length), buffer.readSlice(length))).build();
break;
default:
LOG.info("Unknown type of range sub-tlv: {}", type);
buffer.skipBytes(length);
continue;
}
subTlvs.add(new SubTlvsBuilder().setRangeSubTlv(subTlvCase).build());
}
return subTlvs;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.ProtocolId in project bgpcep by opendaylight.
the class RangeTlvParser method parseSrRange.
public static SrRange parseSrRange(final ByteBuf buffer, final ProtocolId protocolId) {
final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
final SrRangeBuilder range = new SrRangeBuilder();
if (protocolId.equals(ProtocolId.Ospf)) {
range.setInterArea(flags.get(INNER_AREA));
} else {
range.setInterArea(Boolean.FALSE);
}
buffer.skipBytes(RESERVED);
range.setRangeSize(readUint16(buffer));
range.setSubTlvs(parseRangeSubTlvs(buffer, protocolId));
return range.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.ProtocolId in project bgpcep by opendaylight.
the class SrLinkAttributesParser method parseLanAdjacencySegmentIdentifier.
public static SrLanAdjIds parseLanAdjacencySegmentIdentifier(final ByteBuf buffer, final ProtocolId protocolId) {
if (!buffer.isReadable()) {
return new SrLanAdjIdsBuilder().build();
}
final SrLanAdjIdsBuilder srLanAdjIdBuilder = new SrLanAdjIdsBuilder();
final BitArray flags = BitArray.valueOf(buffer, FLAGS_BITS_SIZE);
srLanAdjIdBuilder.setFlags(parseFlags(flags, protocolId));
srLanAdjIdBuilder.setWeight(new Weight(readUint8(buffer)));
buffer.skipBytes(RESERVED);
final boolean isValue;
final boolean isLocal;
switch(protocolId) {
case IsisLevel1:
case IsisLevel2:
isValue = flags.get(VALUE_ISIS);
isLocal = flags.get(LOCAL_ISIS);
srLanAdjIdBuilder.setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(buffer, ISO_SYSTEM_ID_SIZE)));
break;
case Ospf:
case OspfV3:
isValue = flags.get(VALUE_OSPF);
isLocal = flags.get(LOCAL_OSPF);
srLanAdjIdBuilder.setNeighborId(Ipv4Util.addressForByteBuf(buffer));
break;
default:
return null;
}
// length determines a type of next field, which is used for parsing
srLanAdjIdBuilder.setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndexByFlags(Size.forValue(buffer.readableBytes()), buffer, isValue, isLocal));
return srLanAdjIdBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.ProtocolId in project bgpcep by opendaylight.
the class LinkstateNlriParserTest method testPrefixNlri.
@Test
public void testPrefixNlri() throws BGPParsingException {
setUp(this.prefixNlri);
// test BA form
assertNull(this.dest.getRouteDistinguisher());
assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
assertEquals(Uint64.ONE, this.dest.getIdentifier().getValue());
final PrefixCase pCase = (PrefixCase) this.dest.getObjectType();
final AdvertisingNodeDescriptors local = pCase.getAdvertisingNodeDescriptors();
assertEquals(new AsNumber(Uint32.valueOf(72)), local.getAsNumber());
assertEquals(new DomainIdentifier(Uint32.valueOf(0x28282828L)), local.getDomainId());
assertEquals(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
final PrefixDescriptors pd = pCase.getPrefixDescriptors();
assertEquals(OspfRouteType.External1, pd.getOspfRouteType());
assertEquals(new TopologyIdentifier(Uint16.valueOf(15)), pd.getMultiTopologyId());
assertEquals(new Ipv4Prefix("255.255.0.0/16"), pd.getIpReachabilityInformation().getIpv4Prefix());
final ByteBuf buffer = Unpooled.buffer();
this.registry.serializeNlriType(this.dest, buffer);
assertArrayEquals(this.prefixNlri, ByteArray.readAllBytes(buffer));
// test BI form
final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create();
linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
protocolId.withValue("isis-level2");
linkstateBI.addChild(protocolId.build());
final ImmutableLeafNodeBuilder<Uint64> identifier = new ImmutableLeafNodeBuilder<>();
identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
identifier.withValue(Uint64.ONE);
linkstateBI.addChild(identifier.build());
final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
// advertising node descriptors
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> advertisingNodeDescriptors = Builders.containerBuilder();
advertisingNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.ADVERTISING_NODE_DESCRIPTORS_NID);
final ImmutableLeafNodeBuilder<Uint32> asNumber = new ImmutableLeafNodeBuilder<>();
asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
asNumber.withValue(Uint32.valueOf(72));
advertisingNodeDescriptors.addChild(asNumber.build());
final ImmutableLeafNodeBuilder<Uint32> domainID = new ImmutableLeafNodeBuilder<>();
domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
domainID.withValue(Uint32.valueOf(673720360L));
advertisingNodeDescriptors.addChild(domainID.build());
final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);
final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x42 });
isisNode.addChild(isoSystemID.build());
crouterId.addChild(isisNode.build());
advertisingNodeDescriptors.addChild(crouterId.build());
// prefix descriptors
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> prefixDescriptors = Builders.containerBuilder();
prefixDescriptors.withNodeIdentifier(LinkstateNlriParser.PREFIX_DESCRIPTORS_NID);
prefixDescriptors.addChild(asNumber.build());
prefixDescriptors.addChild(domainID.build());
final ImmutableLeafNodeBuilder<Uint16> multiTopologyId = new ImmutableLeafNodeBuilder<>();
multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
multiTopologyId.withValue(Uint16.valueOf(15));
prefixDescriptors.addChild(multiTopologyId.build());
final ImmutableLeafNodeBuilder<String> ipReachabilityInformation = new ImmutableLeafNodeBuilder<>();
ipReachabilityInformation.withNodeIdentifier(IP_REACH_NID);
ipReachabilityInformation.withValue("255.255.0.0/16");
prefixDescriptors.addChild(ipReachabilityInformation.build());
final ImmutableLeafNodeBuilder<String> ospfRouteType = new ImmutableLeafNodeBuilder<>();
ospfRouteType.withNodeIdentifier(OSPF_ROUTE_NID);
ospfRouteType.withValue("external1");
prefixDescriptors.addChild(ospfRouteType.build());
objectType.addChild(advertisingNodeDescriptors.build());
objectType.addChild(prefixDescriptors.build());
linkstateBI.addChild(objectType.build());
assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.ProtocolId in project bgpcep by opendaylight.
the class LinkstateNlriParserTest method testNodeNlri.
@Test
public void testNodeNlri() throws BGPParsingException {
setUp(this.nodeNlri);
// test BA form
assertNull(this.dest.getRouteDistinguisher());
assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
assertEquals(Uint64.ONE, this.dest.getIdentifier().getValue());
final NodeCase nCase = (NodeCase) this.dest.getObjectType();
final NodeDescriptors nodeD = nCase.getNodeDescriptors();
assertEquals(new AsNumber(Uint32.valueOf(72)), nodeD.getAsNumber());
assertEquals(new DomainIdentifier(Uint32.valueOf(0x28282828L)), nodeD.getDomainId());
assertEquals(new IsisPseudonodeCaseBuilder().setIsisPseudonode(new IsisPseudonodeBuilder().setPsn(Uint8.valueOf(5)).setIsIsRouterIdentifier(new IsIsRouterIdentifierBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { 0, 0, 0, 0, 0, (byte) 0x39 })).build()).build()).build(), nodeD.getCRouterIdentifier());
final ByteBuf buffer = Unpooled.buffer();
this.registry.serializeNlriType(this.dest, buffer);
assertArrayEquals(this.nodeNlri, ByteArray.readAllBytes(buffer));
// test BI form
final DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create();
linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
protocolId.withValue("isis-level2");
linkstateBI.addChild(protocolId.build());
final ImmutableLeafNodeBuilder<Uint64> identifier = new ImmutableLeafNodeBuilder<>();
identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
identifier.withValue(Uint64.ONE);
linkstateBI.addChild(identifier.build());
final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> nodeDescriptors = Builders.containerBuilder();
nodeDescriptors.withNodeIdentifier(LinkstateNlriParser.NODE_DESCRIPTORS_NID);
final ImmutableLeafNodeBuilder<Uint32> asNumber = new ImmutableLeafNodeBuilder<>();
asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
asNumber.withValue(Uint32.valueOf(72));
nodeDescriptors.addChild(asNumber.build());
final ImmutableLeafNodeBuilder<Uint32> areaID = new ImmutableLeafNodeBuilder<>();
areaID.withNodeIdentifier(NodeNlriParser.AREA_NID);
areaID.withValue(Uint32.valueOf(2697513L));
nodeDescriptors.addChild(areaID.build());
final ImmutableLeafNodeBuilder<Uint32> domainID = new ImmutableLeafNodeBuilder<>();
domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
domainID.withValue(Uint32.valueOf(0x28282828L));
nodeDescriptors.addChild(domainID.build());
final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
isisNode.withNodeIdentifier(NodeNlriParser.ISIS_PSEUDONODE_NID);
final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x39 });
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisPseudoRouter = Builders.containerBuilder();
isisPseudoRouter.withNodeIdentifier(NodeNlriParser.ISIS_ROUTER_NID);
isisPseudoRouter.addChild(isoSystemID.build());
isisNode.addChild(isisPseudoRouter.build());
isisNode.addChild(Builders.leafBuilder().withNodeIdentifier(NodeNlriParser.PSN_NID).withValue(Uint8.valueOf(5)).build());
crouterId.addChild(isisNode.build());
nodeDescriptors.addChild(crouterId.build());
objectType.addChild(nodeDescriptors.build());
linkstateBI.addChild(objectType.build());
assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
}
Aggregations