+
+ @Override
+ public void serializeAttribute(DataObject attribute, ByteBuf byteAggregator) {
+ PathAttributes pathAttributes = (PathAttributes) attribute;
+ List<ExtendedCommunities> communitiesList = pathAttributes.getExtendedCommunities();
+ if (communitiesList == null) {
+ return;
+ }
+ for (ExtendedCommunities extendedCommunities : communitiesList) {
+ if (extendedCommunities.getCommSubType() != null) {
+ byteAggregator.writeShort(extendedCommunities.getCommSubType());
+ }
+ if (extendedCommunities.getExtendedCommunity() instanceof AsSpecificExtendedCommunityCase) {
+ AsSpecificExtendedCommunityCase asSpecificExtendedCommunity = (AsSpecificExtendedCommunityCase) extendedCommunities.getExtendedCommunity();
+
+ //TODO resolve types correctly
+ byteAggregator.writeByte(0);
+ byteAggregator.writeByte(1);
+
+ byteAggregator.writeShort(asSpecificExtendedCommunity.getAsSpecificExtendedCommunity().getGlobalAdministrator().getValue().shortValue());
+ byteAggregator.writeBytes(asSpecificExtendedCommunity.getAsSpecificExtendedCommunity().getLocalAdministrator());
+ }
+ if (extendedCommunities.getExtendedCommunity() instanceof Inet4SpecificExtendedCommunityCase) {
+ Inet4SpecificExtendedCommunityCase inet4SpecificExtendedCommunity = (Inet4SpecificExtendedCommunityCase) extendedCommunities.getExtendedCommunity();
+
+ //TODO resolve types correctly
+ byteAggregator.writeByte(1);
+ byteAggregator.writeByte(4);
+
+ byteAggregator.writeBytes(Ipv4Util.bytesForAddress(inet4SpecificExtendedCommunity.getInet4SpecificExtendedCommunity().getGlobalAdministrator()));
+ byteAggregator.writeBytes(inet4SpecificExtendedCommunity.getInet4SpecificExtendedCommunity().getLocalAdministrator());
+ }
+ if (extendedCommunities.getExtendedCommunity() instanceof OpaqueExtendedCommunityCase) {
+ OpaqueExtendedCommunityCase opaqueExtendedCommunity = (OpaqueExtendedCommunityCase) extendedCommunities.getExtendedCommunity();
+ //TODO resolve types correctly
+ byteAggregator.writeByte(3);
+ byteAggregator.writeByte(4);
+
+ byteAggregator.writeBytes(opaqueExtendedCommunity.getOpaqueExtendedCommunity().getValue());
+ }
+ if (extendedCommunities.getExtendedCommunity() instanceof RouteTargetExtendedCommunityCase) {
+ RouteTargetExtendedCommunityCase routeTargetExtendedCommunity = (RouteTargetExtendedCommunityCase) extendedCommunities.getExtendedCommunity();
+ //TODO how to determine, which numbering space global administrator number is originated from
+ byteAggregator.writeByte(0);
+ byteAggregator.writeByte(2);
+
+ byteAggregator.writeShort(routeTargetExtendedCommunity.getRouteTargetExtendedCommunity().getGlobalAdministrator().getValue().shortValue());
+ byteAggregator.writeBytes(routeTargetExtendedCommunity.getRouteTargetExtendedCommunity().getLocalAdministrator());
+ }
+ if (extendedCommunities.getExtendedCommunity() instanceof RouteOriginExtendedCommunityCase) {
+ RouteOriginExtendedCommunityCase routeOriginExtendedCommunity = (RouteOriginExtendedCommunityCase) extendedCommunities.getExtendedCommunity();
+ //TODO how to determine, which numbering space global administrator number is originated from
+ byteAggregator.writeByte(2);
+ byteAggregator.writeByte(3);
+ byteAggregator.writeShort(routeOriginExtendedCommunity.getRouteOriginExtendedCommunity().getGlobalAdministrator().getValue().shortValue());
+ byteAggregator.writeBytes(routeOriginExtendedCommunity.getRouteOriginExtendedCommunity().getLocalAdministrator());
+ }
+ }
+ }
+}