use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop in project bgpcep by opendaylight.
the class AbstractRIBSupport method buildReach.
/**
* Build MpReachNlri object from DOM representation.
*
* @param routes Collection of MapEntryNode DOM representation of routes
* @param hop CNextHop as it was parsed from Attributes, to be included in MpReach object
* @return MpReachNlri
*/
private MpReachNlri buildReach(final Collection<MapEntryNode> routes, final CNextHop hop) {
final MpReachNlriBuilder mb = new MpReachNlriBuilder();
mb.setAfi(this.getAfi());
mb.setSafi(this.getSafi());
mb.setCNextHop(hop);
mb.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(buildDestination(routes)).build());
return mb.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop in project bgpcep by opendaylight.
the class NextHopUtilTest method testSerializeNextHop.
@Test
public void testSerializeNextHop() {
CNextHop hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(IPV4).build()).build();
final ByteBuf buffer = Unpooled.buffer();
NextHopUtil.serializeNextHop(hop, buffer);
assertArrayEquals(IPV4B, ByteArray.readAllBytes(buffer));
hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IPV6).build()).build();
buffer.clear();
NextHopUtil.serializeNextHop(hop, buffer);
assertArrayEquals(IPV6B, ByteArray.readAllBytes(buffer));
hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IPV6).setLinkLocal(IPV6L).build()).build();
buffer.clear();
NextHopUtil.serializeNextHop(hop, buffer);
assertArrayEquals(IPV6LB, ByteArray.readAllBytes(buffer));
buffer.clear();
hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setLinkLocal(IPV6L).build()).build();
buffer.clear();
try {
NextHopUtil.serializeNextHop(hop, buffer);
fail("Exception should happen");
} catch (final IllegalArgumentException e) {
assertEquals("Ipv6 Next Hop is missing Global address.", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop in project bgpcep by opendaylight.
the class BgpTestActivator method startImpl.
@Override
protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
initMock();
final List<AutoCloseable> regs = Lists.newArrayList();
regs.add(context.registerAttributeParser(TYPE, this.attrParser));
regs.add(context.registerAttributeSerializer(DataObject.class, this.attrSerializer));
regs.add(context.registerParameterParser(TYPE, this.paramParser));
regs.add(context.registerParameterSerializer(BgpParameters.class, this.paramSerializer));
regs.add(context.registerCapabilityParser(TYPE, this.capaParser));
regs.add(context.registerCapabilitySerializer(CParameters.class, this.capaSerializer));
regs.add(context.registerBgpPrefixSidTlvParser(TYPE, this.sidTlvParser));
regs.add(context.registerBgpPrefixSidTlvSerializer(BgpPrefixSidTlv.class, this.sidTlvSerializer));
regs.add(context.registerMessageParser(TYPE, this.msgParser));
regs.add(context.registerMessageSerializer(Notification.class, this.msgSerializer));
regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, 1));
regs.add(context.registerAddressFamily(Ipv6AddressFamily.class, 2));
regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, 1));
this.nextHopParserSerializer = new NextHopParserSerializer() {
@Override
public CNextHop parseNextHop(final ByteBuf buffer) throws BGPParsingException {
return new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("127.0.0.1")).build()).build();
}
@Override
public void serializeNextHop(final CNextHop cNextHop, final ByteBuf byteAggregator) {
final byte[] mpReachBytes = { 0x7f, 0x00, 0x00, 0x01 };
byteAggregator.writeBytes(mpReachBytes);
}
};
regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, this.nlriParser, this.nextHopParserSerializer, Ipv4NextHopCase.class));
regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, this.nlriParser, this.nextHopParserSerializer, Ipv6NextHopCase.class));
regs.add(context.registerNlriSerializer(DataObject.class, this.nlriSerializer));
regs.add(context.registerExtendedCommunityParser(0, 0, this.exParser));
regs.add(context.registerExtendedCommunitySerializer(RouteTargetIpv4Case.class, this.exSerializer));
return regs;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop in project bgpcep by opendaylight.
the class SimpleNlriRegistry method serializeMpReach.
@Override
public void serializeMpReach(final MpReachNlri mpReachNlri, final ByteBuf byteAggregator) {
final Class<? extends AddressFamily> afi = mpReachNlri.getAfi();
final Class<? extends SubsequentAddressFamily> safi = mpReachNlri.getSafi();
byteAggregator.writeShort(this.afiReg.numberForClass(afi));
byteAggregator.writeByte(this.safiReg.numberForClass(safi));
final CNextHop cNextHop = mpReachNlri.getCNextHop();
if (cNextHop != null) {
final Entry<Class<? extends CNextHop>, BgpTableType> key = new SimpleEntry(cNextHop.getImplementedInterface(), new BgpTableTypeImpl(afi, safi));
final NextHopParserSerializer nextHopSerializer = this.nextHopSerializers.get(key);
final ByteBuf nextHopBuffer = Unpooled.buffer();
nextHopSerializer.serializeNextHop(cNextHop, nextHopBuffer);
byteAggregator.writeByte(nextHopBuffer.writerIndex());
byteAggregator.writeBytes(nextHopBuffer);
} else {
byteAggregator.writeZero(NEXT_HOP_LENGHT);
}
byteAggregator.writeZero(RESERVED);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop in project bgpcep by opendaylight.
the class SimpleNlriRegistry method registerNlriParser.
synchronized AutoCloseable registerNlriParser(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi, final NlriParser parser, final NextHopParserSerializer nextHopSerializer, final Class<? extends CNextHop> cNextHopClass, final Class<? extends CNextHop>... cNextHopClassList) {
final BgpTableType key = createKey(afi, safi);
final NlriParser prev = this.handlers.get(key);
Preconditions.checkState(prev == null, "AFI/SAFI is already bound to parser " + prev);
this.handlers.put(key, parser);
this.nextHopParsers.put(key, nextHopSerializer);
if (cNextHopClass != null) {
final Entry<Class<? extends CNextHop>, BgpTableType> nhKey = new SimpleEntry<>(cNextHopClass, key);
this.nextHopSerializers.put(nhKey, nextHopSerializer);
for (final Class<? extends CNextHop> cNextHop : cNextHopClassList) {
final Entry<Class<? extends CNextHop>, BgpTableType> nhKeys = new SimpleEntry<>(cNextHop, key);
this.nextHopSerializers.put(nhKeys, nextHopSerializer);
}
}
final Object lock = this;
return new AbstractRegistration() {
@Override
protected void removeRegistration() {
synchronized (lock) {
SimpleNlriRegistry.this.handlers.remove(key);
SimpleNlriRegistry.this.nextHopParsers.remove(key);
if (cNextHopClass != null) {
final Entry<Class<? extends CNextHop>, BgpTableType> nhKey = new SimpleEntry<>(cNextHopClass, key);
SimpleNlriRegistry.this.nextHopSerializers.remove(nhKey);
for (final Class<? extends CNextHop> cNextHop : cNextHopClassList) {
final Entry<Class<? extends CNextHop>, BgpTableType> nhKeys = new SimpleEntry<>(cNextHop, key);
SimpleNlriRegistry.this.nextHopSerializers.remove(nhKeys);
}
}
}
}
};
}
Aggregations