use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapability in project bgpcep by opendaylight.
the class GracefulCapabilityHandler method serializeCapability.
private ByteBuf serializeCapability(final GracefulRestartCapability grace) {
final List<Tables> tables = grace.getTables();
final int tablesSize = (tables != null) ? tables.size() : 0;
final ByteBuf bytes = Unpooled.buffer(HEADER_SIZE + (PER_AFI_SAFI_SIZE * tablesSize));
int timeval = 0;
Integer time = grace.getRestartTime();
if (time == null) {
time = 0;
}
Preconditions.checkArgument(time >= 0 && time <= MAX_RESTART_TIME, "Restart time is " + time);
timeval = time;
final GracefulRestartCapability.RestartFlags flags = grace.getRestartFlags();
if (flags != null && flags.isRestartState()) {
writeUnsignedShort(RESTART_FLAG_STATE | timeval, bytes);
} else {
writeUnsignedShort(timeval, bytes);
}
serializeTables(tables, bytes);
return bytes;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapability in project bgpcep by opendaylight.
the class ComplementaryTest method testBGPParameter.
@Test
public void testBGPParameter() {
final MultiprotocolCapability cap = new MultiprotocolCapabilityBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build();
final CParameters tlv1 = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(cap).build()).build();
final MultiprotocolCapability cap1 = new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build();
final CParameters tlv2 = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(cap1).build()).build();
final List<Tables> tt = new ArrayList<>();
tt.add(new TablesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build());
tt.add(new TablesBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build());
final GracefulRestartCapability tlv3 = new GracefulRestartCapabilityBuilder().setRestartFlags(new RestartFlags(Boolean.FALSE)).setRestartTime(0).setTables(tt).build();
final CParameters tlv4 = new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) 40)).build()).build();
assertFalse(tlv3.getRestartFlags().isRestartState());
assertEquals(0, tlv3.getRestartTime().intValue());
assertFalse(tlv1.equals(tlv2));
assertNotSame(tlv1.hashCode(), tlv3.hashCode());
assertNotSame(tlv2.toString(), tlv3.toString());
assertEquals(tlv3.getTables(), tt);
assertEquals(cap.getSafi(), cap1.getSafi());
assertNotSame(cap.getAfi(), cap1.getAfi());
assertEquals(40, tlv4.getAs4BytesCapability().getAsNumber().getValue().longValue());
assertEquals(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) 40)).build()).build(), tlv4);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapability in project bgpcep by opendaylight.
the class GracefulCapabilityHandler method serializeCapability.
@Override
public void serializeCapability(final CParameters capability, final ByteBuf byteAggregator) {
if (capability.getAugmentation(CParameters1.class) == null || capability.getAugmentation(CParameters1.class).getGracefulRestartCapability() == null) {
return;
}
final GracefulRestartCapability grace = capability.getAugmentation(CParameters1.class).getGracefulRestartCapability();
final ByteBuf bytes = serializeCapability(grace);
CapabilityUtil.formatCapability(CODE, bytes, byteAggregator);
}
Aggregations