use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class OpenConfigMappingUtilTest method toPathSelectionMode.
@Test
public void toPathSelectionMode() {
final List<AfiSafi> families = new ArrayList<>();
families.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class).addAugmentation(GlobalAddPathsConfig.class, new GlobalAddPathsConfigBuilder().setSendMax(Shorts.checkedCast(N_PATHS)).build()).build());
families.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class).addAugmentation(GlobalAddPathsConfig.class, new GlobalAddPathsConfigBuilder().setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
final Map<BgpTableType, PathSelectionMode> result = OpenConfigMappingUtil.toPathSelectionMode(families, this.tableTypeRegistry, PEER_TRACKER);
final Map<BgpTableType, PathSelectionMode> expected = new HashMap<>();
expected.put(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), ADD_PATH_BEST_N_PATH_SELECTION);
expected.put(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class), ADD_PATH_BEST_ALL_PATH_SELECTION);
assertEquals(expected.get(0), result.get(0));
assertEquals(expected.get(1), result.get(1));
}
use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class EventBusRegistration method sendMessage.
private static void sendMessage(final BGPSessionListener listener, final Notification message) {
if (BGPMock.CONNECTION_LOST_MAGIC_MSG.equals(message)) {
listener.onSessionTerminated(null, new BGPTerminationReason(BGPError.CEASE));
} else if (message instanceof Open) {
final Set<BgpTableType> tts = Sets.newHashSet();
final List<AddressFamilies> addPathCapabilitiesList = Lists.newArrayList();
for (final BgpParameters param : ((Open) message).getBgpParameters()) {
for (final OptionalCapabilities capa : param.getOptionalCapabilities()) {
final CParameters cParam = capa.getCParameters();
if (cParam.getAugmentation(CParameters1.class) == null) {
continue;
}
if (cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability() != null) {
final MultiprotocolCapability p = cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability();
LOG.debug("Adding open parameter {}", p);
final BgpTableType type = new BgpTableTypeImpl(p.getAfi(), p.getSafi());
tts.add(type);
} else if (cParam.getAugmentation(CParameters1.class).getAddPathCapability() != null) {
final AddPathCapability addPathCap = cParam.getAugmentation(CParameters1.class).getAddPathCapability();
addPathCapabilitiesList.addAll(addPathCap.getAddressFamilies());
}
}
}
listener.onSessionUp(new MockBGPSession(tts));
} else if (!(message instanceof Keepalive)) {
try {
listener.onMessage(new MockBGPSession(), message);
} catch (BGPDocumentedException e) {
LOG.warn("Exception encountered while handling message", e);
}
}
}
use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class SimpleBGPTableTypeRegistryProvider method registerBGPTableType.
@Override
public synchronized AbstractRegistration registerBGPTableType(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi, final Class<? extends AfiSafiType> afiSafiType) {
final BgpTableType tableType = new BgpTableTypeImpl(afi, safi);
final Class<? extends AfiSafiType> prev = this.tableTypes.putIfAbsent(tableType, afiSafiType);
Preconditions.checkState(prev == null, "AFI %s SAFI %s is already registered with %s", afi, safi, prev);
final TablesKey tableKey = new TablesKey(tableType.getAfi(), tableType.getSafi());
this.tableKeys.put(tableKey, afiSafiType);
return new AbstractRegistration() {
@Override
protected void removeRegistration() {
synchronized (SimpleBGPTableTypeRegistryProvider.this) {
SimpleBGPTableTypeRegistryProvider.this.tableTypes.remove(tableType);
SimpleBGPTableTypeRegistryProvider.this.tableKeys.remove(tableKey);
}
}
};
}
use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class SimpleBGPTableTypeRegistryProviderTest method testBGPTableTypeRegistryProvider.
@Test
public void testBGPTableTypeRegistryProvider() {
final Optional<Class<? extends AfiSafiType>> afiSafiType = this.provider.getAfiSafiType(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
Assert.assertTrue(afiSafiType.isPresent());
final Optional<Class<? extends AfiSafiType>> afiSafiType2 = this.provider.getAfiSafiType(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
Assert.assertFalse(afiSafiType2.isPresent());
final Optional<BgpTableType> tableType = this.provider.getTableType(IPV4UNICAST.class);
Assert.assertTrue(tableType.isPresent());
final Optional<BgpTableType> tableType2 = this.provider.getTableType(IPV6UNICAST.class);
Assert.assertFalse(tableType2.isPresent());
this.registration.close();
final Optional<BgpTableType> tableType3 = this.provider.getTableType(IPV4UNICAST.class);
Assert.assertFalse(tableType3.isPresent());
}
use of org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl in project bgpcep by opendaylight.
the class ParserToSalTest method testWithLinkstate.
@Test
public void testWithLinkstate() throws ReadFailedException {
final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
final RIBImpl rib = new RIBImpl(new RibId(TEST_RIB_ID), AS_NUMBER, BGP_ID, this.ext2, this.dispatcher, this.codecsRegistry, getDomBroker(), getDataBroker(), this.policies, this.peerTracker, tables, Collections.singletonMap(TABLE_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker)));
rib.instantiateServiceInstance();
assertTablesExists(tables);
rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
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();
}
Aggregations