@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final Attributes pathAttributes = (Attributes) attribute; if (pathAttributes.getAtomicAggregate() == null) { return; } AttributeUtil.formatAttribute(AttributeUtil.TRANSITIVE, TYPE, Unpooled.EMPTY_BUFFER, byteAggregator); } }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final CNextHop cNextHop = ((Attributes) attribute).getCNextHop(); if (cNextHop == null) { return; } final ByteBuf nextHopBuffer = Unpooled.buffer(); NextHopUtil.serializeNextHop(cNextHop, nextHopBuffer); AttributeUtil.formatAttribute(AttributeUtil.TRANSITIVE, TYPE, nextHopBuffer, byteAggregator); } }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final List<ExtendedCommunities> communitiesList = ((Attributes) attribute).getExtendedCommunities(); if (communitiesList == null || communitiesList.isEmpty()) { return; } final ByteBuf extendedCommunitiesBuffer = Unpooled.buffer(); for (final ExtendedCommunities extendedCommunities : communitiesList) { this.ecReg.serializeExtendedCommunity(extendedCommunities, extendedCommunitiesBuffer); } if (extendedCommunitiesBuffer.readableBytes() > 0) { AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL | AttributeUtil.TRANSITIVE, TYPE, extendedCommunitiesBuffer, byteAggregator); } } }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final Aigp aigpAttribute = ((Attributes) attribute).getAigp(); if (aigpAttribute == null) { return; } AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, serializeAigpTLV(aigpAttribute), byteAggregator); }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final OriginatorId originator = ((Attributes) attribute).getOriginatorId(); if (originator == null) { return; } final ByteBuf originatorIdBuf = Unpooled.buffer(); originatorIdBuf.writeBytes(Ipv4Util.bytesForAddress(originator.getOriginator())); AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, originatorIdBuf, byteAggregator); } }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final LocalPref lp = ((Attributes) attribute).getLocalPref(); if (lp == null) { return; } AttributeUtil.formatAttribute(AttributeUtil.TRANSITIVE, TYPE, Unpooled.copyInt(lp.getPref().intValue()), byteAggregator); } }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final MultiExitDisc multiExitDisc = ((Attributes) attribute).getMultiExitDisc(); if (multiExitDisc == null) { return; } AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, Unpooled.copyInt(multiExitDisc.getMed().intValue()), byteAggregator); } }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final Origin origin = ((Attributes) attribute).getOrigin(); if (origin == null) { return; } AttributeUtil.formatAttribute(AttributeUtil.TRANSITIVE, TYPE, Unpooled.wrappedBuffer(new byte[] {UnsignedBytes.checkedCast(origin.getValue().getIntValue())}), byteAggregator); } }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final List<Communities> communities = ((Attributes) attribute).getCommunities(); if (communities == null || communities.isEmpty()) { return; } final ByteBuf communitiesBuffer = Unpooled.buffer(); for (final Community community : communities) { communitiesBuffer.writeShort(community.getAsNumber().getValue().shortValue()); communitiesBuffer.writeShort(community.getSemantics().shortValue()); } AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL | AttributeUtil.TRANSITIVE, TYPE, communitiesBuffer, byteAggregator); } }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final ClusterId cid = ((Attributes) attribute).getClusterId(); if (cid == null) { return; } final List<ClusterIdentifier> cluster = cid.getCluster(); if (cluster == null || cluster.isEmpty()) { return; } final ByteBuf clusterIdBuffer = Unpooled.buffer(); for (final ClusterIdentifier clusterIdentifier : cid.getCluster()) { clusterIdBuffer.writeBytes(Ipv4Util.bytesForAddress(clusterIdentifier)); } AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, clusterIdBuffer, byteAggregator); } }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final Attributes pathAttributes = (Attributes) attribute; final Aggregator aggregator = pathAttributes.getAggregator(); if (aggregator == null) { return; } Preconditions.checkArgument(aggregator.getAsNumber() != null, "Missing AS number that formed the aggregate route (encoded as 2 octets)."); final ShortAsNumber shortAsNumber = new ShortAsNumber(aggregator.getAsNumber()); final ByteBuf buffer = Unpooled.buffer(); buffer.writeInt(shortAsNumber.getValue().intValue()); buffer.writeBytes(Ipv4Util.bytesForAddress(aggregator.getNetworkAddress())); AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL | AttributeUtil.TRANSITIVE, TYPE, buffer, byteAggregator); } }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final Attributes pathAttributes = (Attributes) attribute; final Attributes2 pathAttributes2 = pathAttributes.getAugmentation(Attributes2.class); if (pathAttributes2 == null) { return; } final MpUnreachNlri mpUnreachNlri = pathAttributes2.getMpUnreachNlri(); final ByteBuf unreachBuffer = Unpooled.buffer(); this.reg.serializeMpUnReach(mpUnreachNlri, unreachBuffer); for (final NlriSerializer nlriSerializer : this.reg.getSerializers()){ nlriSerializer.serializeAttribute(attribute,unreachBuffer); } AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, unreachBuffer, byteAggregator); } }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final Attributes pathAttributes = (Attributes) attribute; final Attributes1 pathAttributes1 = pathAttributes.getAugmentation(Attributes1.class); if (pathAttributes1 == null) { return; } final MpReachNlri mpReachNlri = pathAttributes1.getMpReachNlri(); final ByteBuf reachBuffer = Unpooled.buffer(); this.reg.serializeMpReach(mpReachNlri, reachBuffer); for (final NlriSerializer nlriSerializer : this.reg.getSerializers()) { nlriSerializer.serializeAttribute(attribute, reachBuffer); } AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, reachBuffer, byteAggregator); } }
@Override public void serializeAttribute(final DataObject attributes, final ByteBuf byteAggregator) { Preconditions.checkArgument(attributes instanceof Attributes, "Attributes parameter is not a PathAttribute object."); final List<UnrecognizedAttributes> unrecognizedAttrs = ((Attributes) attributes).getUnrecognizedAttributes(); if (unrecognizedAttrs == null) { return; } for (final UnrecognizedAttributes unrecognizedAttr: unrecognizedAttrs) { LOG.trace("Serializing unrecognized attribute of type {}", unrecognizedAttr.getType()); int flags = AttributeUtil.OPTIONAL; if (unrecognizedAttr.isPartial()) { flags |= AttributeUtil.PARTIAL; } if (unrecognizedAttr.isTransitive()) { flags |= AttributeUtil.TRANSITIVE; } AttributeUtil.formatAttribute(flags, unrecognizedAttr.getType(), Unpooled.wrappedBuffer(unrecognizedAttr.getValue()), byteAggregator); } }
/** * 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); } }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final Attributes pathAttributes = (Attributes) attribute; final AsPath asPath = pathAttributes.getAsPath(); if (asPath == null) { return; } final ByteBuf segmentsBuffer = Unpooled.buffer(); if (asPath.getSegments() != null) { for (final Segments segments : asPath.getSegments()) { if (segments.getAsSequence() != null) { AsPathSegmentParser.serializeAsList(segments.getAsSequence(), SegmentType.AS_SEQUENCE, segmentsBuffer); } else if (segments.getAsSet() != null) { AsPathSegmentParser.serializeAsList(segments.getAsSet(), SegmentType.AS_SET, segmentsBuffer); } else { LOG.warn("Segment doesn't have AsSequence nor AsSet list."); } } } AttributeUtil.formatAttribute(AttributeUtil.TRANSITIVE, TYPE, segmentsBuffer, byteAggregator); } }