use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ProtocolVersion in project bgpcep by opendaylight.
the class BGPMessageParserMockTest method testGetOpenMessage.
@Test
public void testGetOpenMessage() throws BGPParsingException, BGPDocumentedException {
final Map<ByteBuf, Notification> openMap = new HashMap<>();
final Set<BgpTableType> type = new HashSet<>();
type.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class));
final List<BgpParameters> params = new ArrayList<>();
final CParameters par = new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(MplsLabeledVpnSubsequentAddressFamily.class).build()).build()).build();
params.add(new BgpParametersBuilder().setOptionalCapabilities(Lists.newArrayList(new OptionalCapabilitiesBuilder().setCParameters(par).build())).build());
final byte[] input = new byte[] { 5, 8, 13, 21 };
openMap.put(Unpooled.copiedBuffer(input), new OpenBuilder().setMyAsNumber(Uint16.valueOf(30)).setHoldTimer(Uint16.valueOf(30)).setBgpParameters(params).setVersion(new ProtocolVersion(Uint8.valueOf(4))).build());
final BGPMessageParserMock mockParser = new BGPMessageParserMock(openMap);
final Set<BgpTableType> result = new HashSet<>();
for (final BgpParameters p : ((Open) mockParser.parseMessage(Unpooled.copiedBuffer(input), null)).getBgpParameters()) {
for (final OptionalCapabilities capa : p.getOptionalCapabilities()) {
final CParameters cp = capa.getCParameters();
if (cp.augmentation(CParameters1.class) != null && cp.augmentation(CParameters1.class).getMultiprotocolCapability() != null) {
final BgpTableType t = new BgpTableTypeImpl(cp.augmentation(CParameters1.class).getMultiprotocolCapability().getAfi(), cp.augmentation(CParameters1.class).getMultiprotocolCapability().getSafi());
result.add(t);
}
}
}
assertEquals(type, result);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ProtocolVersion in project bgpcep by opendaylight.
the class ParserTest method testOpenMessage.
@Test
public void testOpenMessage() throws BGPParsingException, BGPDocumentedException {
final Notification open = new OpenBuilder().setMyAsNumber(Uint16.valueOf(100)).setHoldTimer(Uint16.valueOf(180)).setBgpIdentifier(new Ipv4AddressNoZone("20.20.20.20")).setVersion(new ProtocolVersion(Uint8.valueOf(4))).build();
final ByteBuf bytes = Unpooled.buffer();
ParserTest.reg.serializeMessage(open, bytes);
assertArrayEquals(OPEN_BMSG, ByteArray.getAllBytes(bytes));
final Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
assertThat(m, instanceOf(Open.class));
final Open mo = (Open) m;
assertEquals(100, mo.getMyAsNumber().intValue());
assertEquals(180, mo.getHoldTimer().intValue());
assertEquals(new Ipv4Address("20.20.20.20"), mo.getBgpIdentifier());
assertNull(mo.getBgpParameters());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ProtocolVersion in project bgpcep by opendaylight.
the class OpenTest method testSerializeLongOpen.
@Test
public void testSerializeLongOpen() throws BGPDocumentedException {
final List<OptionalCapabilities> capabilities = new ArrayList<>();
for (int i = 0; i < 200; ++i) {
capabilities.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(Uint32.valueOf(1000))).build()).build()).build());
}
final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4AddressNoZone("127.0.0.1")).setMyAsNumber(Uint16.valueOf(30)).setHoldTimer(Uint16.valueOf(3)).setVersion(new ProtocolVersion(Uint8.valueOf(4))).setBgpParameters(List.of(new BgpParametersBuilder().setOptionalCapabilities(capabilities).build())).build();
final ByteBuf msg = Unpooled.buffer();
new BGPOpenMessageParser(registry).serializeMessage(open, msg);
assertEquals(1235, msg.readableBytes());
final byte[] temp = ByteArray.cutBytes(ByteArray.getAllBytes(msg), 19);
final Open openResult = new BGPOpenMessageParser(registry).parseMessageBody(Unpooled.copiedBuffer(temp), temp.length, null);
assertEquals(200, openResult.getBgpParameters().get(0).getOptionalCapabilities().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ProtocolVersion in project bgpcep by opendaylight.
the class FSMTest method sendNotification.
@Test
public void sendNotification() {
this.clientSession.channelActive(null);
this.clientSession.handleMessage(this.classicOpen);
this.clientSession.handleMessage(new KeepaliveBuilder().build());
assertEquals(this.clientSession.getState(), BGPClientSessionNegotiator.State.FINISHED);
this.clientSession.handleMessage(new OpenBuilder().setMyAsNumber(Uint16.valueOf(30)).setHoldTimer(Uint16.valueOf(3)).setVersion(new ProtocolVersion(Uint8.valueOf(4))).build());
assertEquals(3, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(2) instanceof Notify);
final Notification m = this.receivedMsgs.get(2);
assertEquals(BGPError.FSM_ERROR.getCode(), ((Notify) m).getErrorCode());
assertEquals(BGPError.FSM_ERROR.getSubcode(), ((Notify) m).getErrorSubcode());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ProtocolVersion in project bgpcep by opendaylight.
the class PCEPOpenObjectParser method parseObject.
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
final int versionValue = ByteArray.copyBitsRange(bytes.readByte(), VERSION_SF_OFFSET, VERSION_SF_LENGTH);
final short keepalive = bytes.readUnsignedByte();
final short deadTimer = bytes.readUnsignedByte();
final Uint8 sessionId = ByteBufUtils.readUint8(bytes);
final TlvsBuilder tbuilder = new TlvsBuilder();
parseTlvs(tbuilder, bytes.slice());
final OpenBuilder builder = new OpenBuilder().setVersion(new ProtocolVersion(Uint8.valueOf(versionValue))).setProcessingRule(header.getProcessingRule()).setIgnore(header.getIgnore()).setKeepalive(Uint8.valueOf(keepalive)).setSessionId(sessionId).setTlvs(tbuilder.build());
if (keepalive == 0) {
builder.setDeadTimer(Uint8.ZERO);
} else {
builder.setDeadTimer(Uint8.valueOf(deadTimer));
}
final Open obj = builder.build();
if (versionValue != PCEP_VERSION) {
// TODO: Should we move this check into the negotiator
LOG.debug("Unsupported PCEP version {}", versionValue);
return new UnknownObject(PCEPErrors.PCEP_VERSION_NOT_SUPPORTED, obj);
}
return obj;
}
Aggregations