use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric in project bgpcep by opendaylight.
the class LinkAttributesParser method parseLinkAttributes.
/**
* Parse Link Attributes.
*
* @param attributes key is the tlv type and value is the value of the tlv
* @param protocolId to differentiate parsing methods
* @return {@link LinkStateAttribute}
*/
static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes, final ProtocolId protocolId) {
final LinkAttributesBuilder builder = new LinkAttributesBuilder();
final List<SrAdjIds> srAdjIds = new ArrayList<>();
final List<SrLanAdjIds> srLanAdjIds = new ArrayList<>();
final List<PeerSetSids> peerSetSids = new ArrayList<>();
for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
LOG.trace("Link attribute TLV {}", entry.getKey());
final int key = entry.getKey();
final ByteBuf value = entry.getValue();
switch(key) {
case TlvUtil.LOCAL_IPV4_ROUTER_ID:
builder.setLocalIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
LOG.debug("Parsed IPv4 Router-ID of local node: {}", builder.getLocalIpv4RouterId());
break;
case TlvUtil.LOCAL_IPV6_ROUTER_ID:
builder.setLocalIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
LOG.debug("Parsed IPv6 Router-ID of local node: {}", builder.getLocalIpv6RouterId());
break;
case REMOTE_IPV4_ROUTER_ID:
builder.setRemoteIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
LOG.debug("Parsed IPv4 Router-ID of remote node: {}", builder.getRemoteIpv4RouterId());
break;
case REMOTE_IPV6_ROUTER_ID:
builder.setRemoteIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
LOG.debug("Parsed IPv6 Router-ID of remote node: {}", builder.getRemoteIpv6RouterId());
break;
case ADMIN_GROUP:
builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt()));
LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
break;
case MAX_BANDWIDTH:
builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
break;
case MAX_RESERVABLE_BANDWIDTH:
builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
break;
case UNRESERVED_BANDWIDTH:
parseUnreservedBandwidth(value, builder);
break;
case TE_METRIC:
builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
LOG.debug("Parsed Metric {}", builder.getTeMetric());
break;
case LINK_PROTECTION_TYPE:
builder.setLinkProtection(LinkProtectionType.forValue(value.readShort()));
LOG.debug("Parsed Link Protection Type {}", builder.getLinkProtection());
break;
case MPLS_PROTOCOL:
final BitArray bits = BitArray.valueOf(value, FLAGS_SIZE);
builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
break;
case METRIC:
// length can 3, 2 or 1
builder.setMetric(new Metric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
LOG.debug("Parsed Metric {}", builder.getMetric());
break;
case SHARED_RISK_LINK_GROUP:
parseSrlg(value, builder);
break;
case LINK_OPAQUE:
LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value));
break;
case LINK_NAME:
builder.setLinkName(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII));
LOG.debug("Parsed Link Name : {}", builder.getLinkName());
break;
case SR_ADJ_ID:
srAdjIds.add(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, protocolId));
LOG.debug("Parsed Adjacency Segment Identifier :{}", srAdjIds.get(srAdjIds.size() - 1));
break;
case SR_LAN_ADJ_ID:
srLanAdjIds.add(SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(value, protocolId));
LOG.debug("Parsed Adjacency Segment Identifier :{}", srLanAdjIds.get(srLanAdjIds.size() - 1));
break;
case PEER_NODE_SID_CODE:
builder.setPeerNodeSid(new PeerNodeSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerNodeSid());
break;
case PEER_ADJ_SID_CODE:
builder.setPeerAdjSid(new PeerAdjSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerAdjSid());
break;
case PEER_SET_SID_CODE:
peerSetSids.add(new PeerSetSidsBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
LOG.debug("Parsed Peer Set Sid :{}", peerSetSids.get(peerSetSids.size() - 1));
break;
default:
LOG.warn("TLV {} is not a valid link attribute, ignoring it", key);
}
}
if (!srAdjIds.isEmpty()) {
builder.setSrAdjIds(srAdjIds);
}
if (!srLanAdjIds.isEmpty()) {
builder.setSrLanAdjIds(srLanAdjIds);
}
if (!peerSetSids.isEmpty()) {
builder.setPeerSetSids(peerSetSids);
}
LOG.trace("Finished parsing Link Attributes.");
return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric in project bgpcep by opendaylight.
the class PrefixAttributesParser method parseAttribute.
private static void parseAttribute(final int key, final ByteBuf value, final ProtocolId protocolId, final PrefixAttributesBuilder builder, final List<RouteTag> routeTags, final List<ExtendedRouteTag> exRouteTags) {
switch(key) {
case IGP_FLAGS:
parseIgpFags(builder, value);
break;
case ROUTE_TAG:
parseRouteTags(routeTags, value);
break;
case EXTENDED_ROUTE_TAG:
parseExtendedRouteTags(exRouteTags, value);
break;
case PREFIX_METRIC:
final IgpMetric metric = new IgpMetric(value.readUnsignedInt());
builder.setPrefixMetric(metric);
LOG.debug("Parsed Metric: {}", metric);
break;
case FORWARDING_ADDRESS:
final IpAddress fwdAddress = parseForwardingAddress(value);
builder.setOspfForwardingAddress(fwdAddress);
LOG.debug("Parsed FWD Address: {}", fwdAddress);
break;
case PREFIX_OPAQUE:
if (LOG.isDebugEnabled()) {
LOG.debug("Parsed Opaque value: {}, not preserving it", ByteBufUtil.hexDump(value));
}
break;
case PREFIX_SID:
final SrPrefix prefix = SrPrefixAttributesParser.parseSrPrefix(value, protocolId);
builder.setSrPrefix(prefix);
LOG.debug("Parsed SR Prefix: {}", prefix);
break;
case IPV6_PREFIX_SID:
final Ipv6SrPrefix ipv6Prefix = Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(value);
builder.setIpv6SrPrefix(ipv6Prefix);
LOG.debug("Parsed Ipv6 SR Prefix: {}", ipv6Prefix);
break;
case RANGE:
final SrRange range = RangeTlvParser.parseSrRange(value, protocolId);
builder.setSrRange(range);
LOG.debug("Parsed SR Range: {}", range);
break;
case BINDING_SID:
parseBindingSid(builder, value, protocolId);
break;
default:
LOG.warn("TLV {} is not a valid prefix attribute, ignoring it", key);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric in project bgpcep by opendaylight.
the class PathAttributeParserTest method testParsingAigpAttributeWithCorrectTLV.
@Test
public void testParsingAigpAttributeWithCorrectTLV() throws BGPDocumentedException, BGPParsingException {
final byte[] value = new byte[] { 1, 0, 11, 0, 0, 0, 0, 0, 0, 0, 8 };
final ByteBuf buffer = Unpooled.buffer();
AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, AigpAttributeParser.TYPE, Unpooled.copiedBuffer(value), buffer);
final BGPExtensionProviderContext providerContext = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance();
final Attributes pathAttributes = providerContext.getAttributeRegistry().parseAttributes(buffer, null);
final Aigp aigp = pathAttributes.getAigp();
final AigpTlv tlv = aigp.getAigpTlv();
assertNotNull("Tlv should not be null.", tlv);
assertEquals("Aigp tlv should have metric with value 8.", 8, tlv.getMetric().getValue().intValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method insertObject.
private static State insertObject(final State state, final List<Object> objects, final List<VendorInformationObject> viObjects, final P2pBuilder builder, final List<Metrics> metrics, final List<Message> errors, final Rp rp) {
final Object obj = objects.get(0);
switch(state) {
case INIT:
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
objects.remove(0);
final Object nextObj = objects.get(0);
if (nextObj instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) {
builder.setReoptimizationBandwidth((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) nextObj);
}
return State.REPORTED_IN;
}
case REPORTED_IN:
if (obj instanceof VendorInformationObject) {
viObjects.add((VendorInformationObject) obj);
return State.REPORTED_IN;
}
case VENDOR_INFO_LIST:
if (obj instanceof LoadBalancing) {
builder.setLoadBalancing((LoadBalancing) obj);
return State.LOAD_BIN;
}
case LOAD_BIN:
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
return State.LSPA_IN;
}
case LSPA_IN:
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
return State.BANDWIDTH_IN;
}
case BANDWIDTH_IN:
if (obj instanceof Metric) {
metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
return State.BANDWIDTH_IN;
}
case METRIC_IN:
if (obj instanceof Iro) {
builder.setIro((Iro) obj);
return State.IRO_IN;
}
case IRO_IN:
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
return State.RRO_IN;
}
case RRO_IN:
if (obj instanceof Xro) {
builder.setXro((Xro) obj);
return State.XRO_IN;
}
case XRO_IN:
if (obj instanceof Of) {
builder.setOf((Of) obj);
return State.OF_IN;
}
case OF_IN:
if (obj instanceof ClassType) {
final ClassType classType = (ClassType) obj;
if (!classType.isProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rp)));
} else {
builder.setClassType(classType);
}
return State.CT_IN;
}
case CT_IN:
case END:
return State.END;
default:
return state;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric in project bgpcep by opendaylight.
the class PCEPMetricObjectParser method parseObject.
@Override
public Metric parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (bytes.readableBytes() != SIZE) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: " + SIZE + ".");
}
bytes.skipBytes(RESERVED);
final BitArray flags = BitArray.valueOf(bytes.readByte());
final MetricBuilder builder = new MetricBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
builder.setBound(flags.get(B_FLAG_OFFSET));
builder.setComputed(flags.get(C_FLAG_OFFSET));
builder.setMetricType(bytes.readUnsignedByte());
builder.setValue(new Float32(ByteArray.readBytes(bytes, METRIC_VALUE_F_LENGTH)));
return builder.build();
}
Aggregations