use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class ParserToSalTest method testWithoutLinkstate.
@Test
public void testWithoutLinkstate() throws ReadFailedException {
final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
final RIBImpl rib = new RIBImpl(new RibId(TEST_RIB_ID), AS_NUMBER, BGP_ID, this.ext1, this.dispatcher, this.codecsRegistry, getDomBroker(), getDataBroker(), this.policies, this.peerTracker, tables, Collections.singletonMap(TABLE_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker)));
rib.instantiateServiceInstance();
rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
assertTablesExists(tables);
final BGPPeer peer = new BGPPeer(this.localAddress, rib, PeerRole.Ibgp, null, Collections.emptySet(), Collections.emptySet());
peer.instantiateServiceInstance();
final ListenerRegistration<?> reg = this.mock.registerUpdateListener(peer);
reg.close();
}
use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class AbstractConfig method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
doReturn(InstanceIdentifier.create(BgpRib.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.Rib.class, new RibKey(RIB_ID))).when(this.rib).getInstanceIdentifier();
doReturn(this.domTx).when(this.rib).createPeerDOMChain(any(TransactionChainListener.class));
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
return getDataBroker().createTransactionChain((TransactionChainListener) args[0]);
}).when(this.rib).createPeerChain(any(TransactionChainListener.class));
doReturn(getDataBroker()).when(this.rib).getDataBroker();
doReturn(AS).when(this.rib).getLocalAs();
doReturn(mock(RIBSupportContextRegistry.class)).when(this.rib).getRibSupportContext();
doReturn(Collections.emptySet()).when(this.rib).getLocalTablesKeys();
doNothing().when(this.domTx).close();
doReturn(this.domDW).when(this.domTx).newWriteOnlyTransaction();
doNothing().when(this.domDW).put(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(MapEntryNode.class));
doNothing().when(this.domDW).delete(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class));
doNothing().when(this.domDW).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
final CheckedFuture<?, ?> checkedFuture = mock(CheckedFuture.class);
doAnswer(invocation -> {
final Runnable callback = (Runnable) invocation.getArguments()[0];
callback.run();
return null;
}).when(checkedFuture).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
doReturn(checkedFuture).when(this.domDW).submit();
doReturn(null).when(checkedFuture).checkedGet();
doReturn(null).when(checkedFuture).get();
doReturn(true).when(checkedFuture).isDone();
doReturn("checkedFuture").when(checkedFuture).toString();
doReturn(YangInstanceIdentifier.of(Rib.QNAME)).when(this.rib).getYangRibId();
doReturn(this.dataTreeChangeService).when(this.rib).getService();
doReturn(this.listener).when(this.dataTreeChangeService).registerDataTreeChangeListener(any(), any());
doReturn(new BgpId("127.0.0.1")).when(this.rib).getBgpIdentifier();
doReturn(true).when(this.future).cancel(true);
doReturn(this.future).when(this.dispatcher).createReconnectingClient(any(InetSocketAddress.class), anyInt(), any(KeyMapping.class));
doReturn(this.dispatcher).when(this.rib).getDispatcher();
doReturn(java.util.Optional.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class))).when(this.tableTypeRegistry).getTableType(any());
doReturn(java.util.Optional.of(TABLES_KEY)).when(this.tableTypeRegistry).getTableKey(any());
doReturn(Collections.singleton(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class))).when(this.rib).getLocalTables();
doNothing().when(this.bgpPeerRegistry).addPeer(any(IpAddress.class), any(BGPSessionListener.class), any(BGPSessionPreferences.class));
doNothing().when(this.bgpPeerRegistry).removePeer(any(IpAddress.class));
doReturn("registry").when(this.bgpPeerRegistry).toString();
doNothing().when(this.listener).close();
doReturn(this.bgpPeerRegistry).when(this.dispatcher).getBGPPeerRegistry();
doReturn(this.peerTracker).when(this.rib).getPeerTracker();
doReturn(this.policies).when(this.rib).getRibPolicies();
doReturn(null).when(this.peerGroupLoader).getPeerGroup(any(InstanceIdentifier.class), any(String.class));
}
use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class MultiPathSupportImplTest method testIsTableTypeSupported.
@Test
public void testIsTableTypeSupported() {
final List<AddressFamilies> supportedTables = Lists.newArrayList();
final BgpTableType ipv4Unicast = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
final BgpTableType ipv4L3vpn = new BgpTableTypeImpl(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class);
final BgpTableType ipv6Unicast = new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
final BgpTableType ipv6L3vpn = new BgpTableTypeImpl(Ipv6AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class);
supportedTables.add(createAddPathCapability(ipv4Unicast, SendReceive.Send));
supportedTables.add(createAddPathCapability(ipv4L3vpn, SendReceive.Receive));
supportedTables.add(createAddPathCapability(ipv6Unicast, SendReceive.Both));
final MultiPathSupport multiPathSupport = MultiPathSupportImpl.createParserMultiPathSupport(supportedTables);
Assert.assertTrue(multiPathSupport.isTableTypeSupported(ipv4Unicast));
Assert.assertTrue(multiPathSupport.isTableTypeSupported(ipv6Unicast));
Assert.assertFalse(multiPathSupport.isTableTypeSupported(ipv4L3vpn));
Assert.assertFalse(multiPathSupport.isTableTypeSupported(ipv6L3vpn));
}
use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl 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.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class Ipv6NlriParser method prefixes.
private static DestinationIpv6 prefixes(final ByteBuf nlri, final PeerSpecificParserConstraint constraint, final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
final List<Ipv6Prefixes> prefixes = new ArrayList<>();
final boolean supported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(afi, safi));
while (nlri.isReadable()) {
final Ipv6PrefixesBuilder prefixesBuilder = new Ipv6PrefixesBuilder();
if (supported) {
prefixesBuilder.setPathId(PathIdUtil.readPathId(nlri));
}
prefixesBuilder.setPrefix(Ipv6Util.prefixForByteBuf(nlri));
prefixes.add(prefixesBuilder.build());
}
return new DestinationIpv6Builder().setIpv6Prefixes(prefixes).build();
}
Aggregations