use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCase in project bgpcep by opendaylight.
the class LinkstateAttributeParser method serializeAttribute.
/**
* Serialize linkstate attributes.
*
* @param attribute DataObject representing LinkstatePathAttribute
* @param byteAggregator ByteBuf where all serialized data are aggregated
*/
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object.");
final Attributes1 pathAttributes1 = ((Attributes) attribute).getAugmentation(Attributes1.class);
if (pathAttributes1 == null) {
return;
}
final LinkStateAttribute linkState = pathAttributes1.getLinkStateAttribute();
final ByteBuf lsBuffer = Unpooled.buffer();
if (linkState instanceof LinkAttributesCase) {
LinkAttributesParser.serializeLinkAttributes((LinkAttributesCase) linkState, lsBuffer);
} else if (linkState instanceof NodeAttributesCase) {
NodeAttributesParser.serializeNodeAttributes((NodeAttributesCase) linkState, lsBuffer);
} else if (linkState instanceof PrefixAttributesCase) {
PrefixAttributesParser.serializePrefixAttributes((PrefixAttributesCase) linkState, lsBuffer);
} else if (linkState instanceof TeLspAttributesCase) {
TeLspAttributesParser.serializeLspAttributes(this.rsvpTeObjectRegistry, (TeLspAttributesCase) linkState, lsBuffer);
byteAggregator.writeBytes(lsBuffer);
return;
}
AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, getType(), lsBuffer, byteAggregator);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCase in project bgpcep by opendaylight.
the class LinkstateAttributeParserTest method testPositiveLinks.
@Test
public void testPositiveLinks() throws BGPParsingException, BGPDocumentedException {
final AttributesBuilder builder = createBuilder(new LinkCaseBuilder().build());
this.parser.parseAttribute(Unpooled.copiedBuffer(LINK_ATTR), builder, null);
final Attributes1 attrs = builder.augmentation(Attributes1.class);
final LinkAttributes ls = ((LinkAttributesCase) attrs.getLinkStateAttribute()).getLinkAttributes();
assertNotNull(ls);
assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
assertEquals(Uint32.ZERO, ls.getAdminGroup().getValue());
assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 }, ls.getMaxLinkBandwidth().getValue());
assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getMaxReservableBandwidth().getValue());
assertNotNull(ls.getUnreservedBandwidth());
assertEquals(8, ls.getUnreservedBandwidth().size());
assertEquals(LinkProtectionType.Dedicated1to1, ls.getLinkProtection());
assertTrue(ls.getMplsProtocol().getLdp());
assertTrue(ls.getMplsProtocol().getRsvpte());
assertEquals(Uint32.TEN, ls.getMetric().getValue());
assertEquals(2, ls.getSharedRiskLinkGroups().size());
assertEquals(305419896, ls.getSharedRiskLinkGroups().get(0).getValue().intValue());
assertEquals("12K-2", ls.getLinkName());
final IsisAdjFlagsCase flags = new IsisAdjFlagsCaseBuilder().setIsisAdjFlags(new IsisAdjFlagsBuilder().setAddressFamily(Boolean.TRUE).setBackup(Boolean.FALSE).setSet(Boolean.FALSE).build()).build();
assertEquals(flags, ls.getSrAdjIds().get(0).getFlags());
assertEquals(flags, ls.getSrAdjIds().get(1).getFlags());
assertEquals(Uint32.valueOf(1048575L), ((LocalLabelCase) ls.getSrAdjIds().get(0).getSidLabelIndex()).getLocalLabel().getValue());
assertEquals(Uint32.valueOf(1048559L), ((LocalLabelCase) ls.getSrAdjIds().get(1).getSidLabelIndex()).getLocalLabel().getValue());
assertEquals(Uint32.valueOf(168496141L), ((SidCase) ls.getPeerNodeSid().getSidLabelIndex()).getSid());
assertEquals(Uint8.valueOf(5), ls.getPeerNodeSid().getWeight().getValue());
assertEquals(Uint32.valueOf(168496142L), ((SidCase) ls.getPeerSetSids().get(0).getSidLabelIndex()).getSid());
assertEquals(Uint8.valueOf(5), ls.getPeerSetSids().get(0).getWeight().getValue());
assertEquals(Uint32.valueOf(168496143L), ((SidCase) ls.getPeerAdjSid().getSidLabelIndex()).getSid());
assertEquals(Uint8.valueOf(5), ls.getPeerAdjSid().getWeight().getValue());
// Performance Metrics
assertEquals(Uint32.valueOf(10000L), ls.getLinkDelay().getValue());
assertEquals(Uint32.valueOf(5000L), ls.getLinkMinMaxDelay().getMinDelay().getValue());
assertEquals(Uint32.valueOf(20000L), ls.getLinkMinMaxDelay().getMaxDelay().getValue());
assertEquals(Uint32.valueOf(10000L), ls.getDelayVariation().getValue());
assertEquals(Uint32.ZERO, ls.getLinkLoss().getValue());
assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getResidualBandwidth().getValue());
assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getAvailableBandwidth().getValue());
assertArrayEquals(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, ls.getUtilizedBandwidth().getValue());
// serialization
final ByteBuf buff = Unpooled.buffer();
this.parser.serializeAttribute(builder.build(), buff);
// The LINK_ATTR buffer is now greater than 255 bytes. Need to skip one more byte
buff.skipBytes(4);
// there is unresolved TLV at the end, that needs to be cut off
assertArrayEquals(ByteArray.subByte(LINK_ATTR, 0, LINK_ATTR.length - 5), ByteArray.getAllBytes(buff));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCase in project bgpcep by opendaylight.
the class LinkstateTopologyBuilder method createLink.
private void createLink(final WriteTransaction trans, final UriBuilder base, final LinkstateRoute value, final LinkCase linkCase, final Attributes attributes) {
// defensive lookup
final LinkAttributes la;
final Attributes1 attr = attributes.augmentation(Attributes1.class);
if (attr != null) {
final LinkStateAttribute attrType = attr.getLinkStateAttribute();
if (attrType != null) {
la = ((LinkAttributesCase) attrType).getLinkAttributes();
} else {
LOG.debug("Missing attribute type in link {} route {}, skipping it", linkCase, value);
la = null;
}
} else {
LOG.debug("Missing attributes in link {} route {}, skipping it", linkCase, value);
la = null;
}
final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
Long adjSid = null;
if (la != null) {
if (la.getMetric() != null) {
ilab.setMetric(la.getMetric().getValue());
}
ilab.setName(la.getLinkName());
if (la.getSrAdjIds() != null && !la.getSrAdjIds().isEmpty()) {
final SrAdjIds srAdjIds = la.getSrAdjIds().get(0);
if (srAdjIds != null) {
final SidLabelIndex sidLabelIndex = srAdjIds.getSidLabelIndex();
if (sidLabelIndex instanceof LocalLabelCase) {
adjSid = ((LocalLabelCase) sidLabelIndex).getLocalLabel().getValue().longValue();
}
}
}
}
ProtocolUtil.augmentProtocolId(value, ilab, la, linkCase.getLinkDescriptors());
final LinkBuilder lb = new LinkBuilder().setLinkId(buildLinkId(base, linkCase)).addAugmentation(new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
final NodeId srcNode = buildNodeId(base, linkCase.getLocalNodeDescriptors());
LOG.trace("Link {} implies source node {}", linkCase, srcNode);
final NodeId dstNode = buildNodeId(base, linkCase.getRemoteNodeDescriptors());
LOG.trace("Link {} implies destination node {}", linkCase, dstNode);
final TerminationPoint srcTp = buildLocalTp(base, linkCase.getLinkDescriptors());
LOG.trace("Link {} implies source TP {}", linkCase, srcTp);
final TerminationPoint dstTp = buildRemoteTp(base, linkCase.getLinkDescriptors());
LOG.trace("Link {} implies destination TP {}", linkCase, dstTp);
lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
LOG.trace("Created TP {} as link source", srcTp);
NodeHolder snh = this.nodes.get(srcNode);
if (snh == null) {
snh = getNode(srcNode);
snh.addTp(srcTp, lb.getLinkId(), false);
if (adjSid != null) {
snh.createSrHolderIfRequired().addAdjacencySid(trans, false, lb.getLinkId(), adjSid);
}
putNode(trans, snh);
} else {
snh.addTp(srcTp, lb.getLinkId(), false);
if (adjSid != null) {
snh.createSrHolderIfRequired().addAdjacencySid(trans, true, lb.getLinkId(), adjSid);
}
final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(snh.getNodeId()));
trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, srcTp.key()), srcTp);
}
if (adjSid != null) {
lb.addAugmentation(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.Link1Builder().setSegment(new SegmentId(Uint32.valueOf(adjSid))).build());
}
LOG.debug("Created TP {} as link destination", dstTp);
NodeHolder dnh = this.nodes.get(dstNode);
if (dnh == null) {
dnh = getNode(dstNode);
dnh.addTp(dstTp, lb.getLinkId(), true);
putNode(trans, dnh);
} else {
dnh.addTp(dstTp, lb.getLinkId(), true);
final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class, new NodeKey(dnh.getNodeId()));
trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, dstTp.key()), dstTp);
}
final InstanceIdentifier<Link> lid = buildLinkIdentifier(lb.getLinkId());
final Link link = lb.build();
trans.put(LogicalDatastoreType.OPERATIONAL, lid, link);
LOG.debug("Created link {} at {} for {}", link, lid, linkCase);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCase in project bgpcep by opendaylight.
the class LinkAttributesParser method serializeLinkAttributes.
static void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf output) {
final LinkAttributes linkAttributes = linkAttributesCase.getLinkAttributes();
LOG.trace("Started serializing Link Attributes");
ifPresentApply(linkAttributes.getLocalIpv4RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress((Ipv4AddressNoZone) value), output));
ifPresentApply(linkAttributes.getLocalIpv6RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress((Ipv6AddressNoZone) value), output));
ifPresentApply(linkAttributes.getRemoteIpv4RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress((Ipv4AddressNoZone) value), output));
ifPresentApply(linkAttributes.getRemoteIpv6RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress((Ipv6AddressNoZone) value), output));
ifPresentApply(linkAttributes.getAdminGroup(), value -> TlvUtil.writeTLV(ADMIN_GROUP, Unpooled.copyInt(((AdministrativeGroup) value).getValue().intValue()), output));
ifPresentApply(linkAttributes.getMaxLinkBandwidth(), value -> TlvUtil.writeTLV(MAX_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
ifPresentApply(linkAttributes.getMaxReservableBandwidth(), value -> TlvUtil.writeTLV(MAX_RESERVABLE_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
serializeUnreservedBw(linkAttributes.getUnreservedBandwidth(), output);
ifPresentApply(linkAttributes.getTeMetric(), value -> TlvUtil.writeTLV(TE_METRIC, Unpooled.copyLong(((TeMetric) value).getValue().toJava()), output));
ifPresentApply(linkAttributes.getLinkProtection(), value -> TlvUtil.writeTLV(LINK_PROTECTION_TYPE, Unpooled.copyShort(((LinkProtectionType) value).getIntValue()), output));
serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), output);
ifPresentApply(linkAttributes.getMetric(), value -> TlvUtil.writeTLV(METRIC, Unpooled.copyMedium(((Metric) value).getValue().intValue()), output));
serializeSrlg(linkAttributes.getSharedRiskLinkGroups(), output);
ifPresentApply(linkAttributes.getLinkName(), value -> TlvUtil.writeTLV(LINK_NAME, Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode((String) value)), output));
ifPresentApply(linkAttributes.getSrAdjIds(), value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List<SrAdjIds>) value, SR_ADJ_ID, output));
ifPresentApply(linkAttributes.getSrLanAdjIds(), value -> SrLinkAttributesParser.serializeLanAdjacencySegmentIdentifiers((List<SrLanAdjIds>) value, output));
ifPresentApply(linkAttributes.getPeerNodeSid(), value -> TlvUtil.writeTLV(PEER_NODE_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerNodeSid) value), output));
ifPresentApply(linkAttributes.getPeerAdjSid(), value -> TlvUtil.writeTLV(PEER_ADJ_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerAdjSid) value), output));
ifPresentApply(linkAttributes.getPeerSetSids(), value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List<PeerSetSids>) value, PEER_SET_SID_CODE, output));
// Performance Metrics
ifPresentApply(linkAttributes.getLinkDelay(), value -> TlvUtil.writeTLV(LINK_DELAY, Unpooled.copyInt(((Delay) value).getValue().intValue()), output));
serializeLinkMinMaxDelay(linkAttributes.getLinkMinMaxDelay(), output);
ifPresentApply(linkAttributes.getDelayVariation(), value -> TlvUtil.writeTLV(DELAY_VARIATION, Unpooled.copyInt(((Delay) value).getValue().intValue()), output));
ifPresentApply(linkAttributes.getLinkLoss(), value -> TlvUtil.writeTLV(LINK_LOSS, Unpooled.copyInt(((Loss) value).getValue().intValue()), output));
ifPresentApply(linkAttributes.getResidualBandwidth(), value -> TlvUtil.writeTLV(RESIDUAL_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
ifPresentApply(linkAttributes.getAvailableBandwidth(), value -> TlvUtil.writeTLV(AVAILABLE_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
ifPresentApply(linkAttributes.getUtilizedBandwidth(), value -> TlvUtil.writeTLV(UTILIZED_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
LOG.trace("Finished serializing Link Attributes");
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCase in project bgpcep by opendaylight.
the class LinkstateAttributeParser method serializeAttribute.
/**
* Serialize linkstate attributes.
*
* @param attribute DataObject representing LinkstatePathAttribute
* @param byteAggregator ByteBuf where all serialized data are aggregated
*/
@Override
public void serializeAttribute(final Attributes attribute, final ByteBuf byteAggregator) {
final Attributes1 pathAttributes1 = attribute.augmentation(Attributes1.class);
if (pathAttributes1 == null) {
return;
}
final LinkStateAttribute linkState = pathAttributes1.getLinkStateAttribute();
final ByteBuf lsBuffer = Unpooled.buffer();
if (linkState instanceof LinkAttributesCase) {
LinkAttributesParser.serializeLinkAttributes((LinkAttributesCase) linkState, lsBuffer);
} else if (linkState instanceof NodeAttributesCase) {
NodeAttributesParser.serializeNodeAttributes((NodeAttributesCase) linkState, lsBuffer);
} else if (linkState instanceof PrefixAttributesCase) {
PrefixAttributesParser.serializePrefixAttributes((PrefixAttributesCase) linkState, lsBuffer);
} else if (linkState instanceof TeLspAttributesCase) {
TeLspAttributesParser.serializeLspAttributes(this.rsvpTeObjectRegistry, (TeLspAttributesCase) linkState, lsBuffer);
byteAggregator.writeBytes(lsBuffer);
return;
}
AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, getType(), lsBuffer, byteAggregator);
}
Aggregations