use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.ClusterId in project bgpcep by opendaylight.
the class ClusterIdAttributeParserTest method testParseEmptyListAttribute.
@Test
public void testParseEmptyListAttribute() {
final List<ClusterIdentifier> list = Lists.newArrayList();
final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().setCluster(list).build()).build();
final ByteBuf output = Unpooled.buffer();
this.parser.serializeAttribute(clusterId, output);
assertEquals(Unpooled.buffer(), output);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.ClusterId in project bgpcep by opendaylight.
the class ClusterIdAttributeParserTest method testParserAttribute.
@Test
public void testParserAttribute() throws Exception {
final List<ClusterIdentifier> list = Lists.newArrayList();
final Ipv4Address ip1 = new Ipv4Address("192.168.1.1");
final Ipv4Address ip2 = new Ipv4Address("192.168.1.2");
list.add(new ClusterIdentifier(ip1));
list.add(new ClusterIdentifier(ip2));
final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().setCluster(list).build()).build();
final ByteBuf output = Unpooled.buffer();
this.parser.serializeAttribute(clusterId, output);
assertArrayEquals(clusterIdBytes, ByteArray.getAllBytes(output));
AttributesBuilder clusterIdOutput = new AttributesBuilder();
this.parser.parseAttribute(Unpooled.wrappedBuffer(ByteArray.cutBytes(clusterIdBytes, 3)), clusterIdOutput);
assertEquals(clusterId, clusterIdOutput.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.ClusterId in project bgpcep by opendaylight.
the class ClusterIdAttributeParser method serializeAttribute.
@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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.ClusterId in project bgpcep by opendaylight.
the class AbstractAddPathTest method createSimpleUpdate.
private static Update createSimpleUpdate(final Ipv4Prefix prefix, final PathId pathId, final ClusterIdentifier clusterId, final long localPreference) {
final AttributesBuilder attBuilder = new AttributesBuilder();
attBuilder.setLocalPref(new LocalPrefBuilder().setPref(localPreference).build());
attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
if (clusterId != null) {
attBuilder.setClusterId(new ClusterIdBuilder().setCluster(Collections.singletonList(clusterId)).build());
attBuilder.setOriginatorId(new OriginatorIdBuilder().setOriginator(new Ipv4Address(clusterId)).build());
}
addAttributeAugmentation(attBuilder, prefix, pathId);
return new UpdateBuilder().setAttributes(attBuilder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.ClusterId in project bgpcep by opendaylight.
the class ExportAttributeTestUtil method createClusterId.
private static ClusterId createClusterId() {
final ClusterIdentifier cluster1 = new ClusterIdentifier(new Ipv4Address("1.1.1.1"));
final ClusterIdentifier cluster2 = new ClusterIdentifier(new Ipv4Address("1.1.1.2"));
return new ClusterIdBuilder().setCluster(Arrays.asList(CLUSTER, cluster1, cluster2)).build();
}
Aggregations