use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber in project bgpcep by opendaylight.
the class AbstractLocalNodeDescriptorTlvCodec method parseTlvBody.
@Override
public final LocalNodeDescriptors parseTlvBody(final ByteBuf value) {
final Map<QName, Object> parsedSubTlvs = new HashMap<>();
final LocalNodeDescriptorsBuilder builder = new LocalNodeDescriptorsBuilder(parseNodeDescriptor(value, parsedSubTlvs));
builder.setBgpRouterId((Ipv4Address) parsedSubTlvs.get(BgpRouterIdTlvParser.BGP_ROUTER_ID_QNAME));
builder.setMemberAsn((AsNumber) parsedSubTlvs.get(MemAsNumTlvParser.MEMBER_AS_NUMBER_QNAME));
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber in project bgpcep by opendaylight.
the class AbstractRIBTestSetup method mockRib.
public void mockRib() throws Exception {
final RIBExtensionProviderContext context = new SimpleRIBExtensionProviderContext();
final ModuleInfoBackedContext strategy = createClassLoadingStrategy();
final SchemaContext schemaContext = strategy.tryToCreateSchemaContext().get();
this.codecFactory = createCodecFactory(strategy, schemaContext);
final List<BgpTableType> localTables = new ArrayList<>();
localTables.add(new BgpTableTypeImpl(AFI, SAFI));
this.a1 = new RIBActivator();
this.a1.startRIBExtensionProvider(context);
final CodecsRegistryImpl codecsRegistry = CodecsRegistryImpl.create(this.codecFactory, GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
mockedMethods();
doReturn(mock(ClusterSingletonServiceRegistration.class)).when(this.clusterSingletonServiceProvider).registerClusterSingletonService(any(ClusterSingletonService.class));
this.rib = new RIBImpl(new RibId("test"), new AsNumber(5L), RIB_ID, context, this.dispatcher, codecsRegistry, this.dom, getDataBroker(), this.policies, this.peerTracker, localTables, Collections.singletonMap(new TablesKey(AFI, SAFI), BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker)));
this.rib.onGlobalContextUpdated(schemaContext);
this.ribSupport = getRib().getRibSupportContext().getRIBSupport(KEY);
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber in project bgpcep by opendaylight.
the class StrictBGPPeerRegistryTest method testDuplicatePeersLowerAs.
@Test
public void testDuplicatePeersLowerAs() throws Exception {
final AsNumber as2 = new AsNumber(3L);
this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
try {
this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, createOpen(TO, as2));
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.CEASE, e.getError());
return;
}
fail("Same peer cannot be connected twice");
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber in project bgpcep by opendaylight.
the class StrictBGPPeerRegistryTest method testAsMismatch.
@Test
public void testAsMismatch() throws Exception {
final AsNumber as2 = new AsNumber(3L);
this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
try {
this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, createOpen(TO, as2));
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.BAD_PEER_AS, e.getError());
return;
}
fail("Peer AS number mismatch");
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber in project bgpcep by opendaylight.
the class StrictBGPPeerRegistry method getPeer.
@Override
public synchronized BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId, final Open openObj) throws BGPDocumentedException {
requireNonNull(ip);
requireNonNull(sourceId);
requireNonNull(remoteId);
final AsNumber remoteAsNumber = AsNumberUtil.advertizedAsNumber(openObj);
requireNonNull(remoteAsNumber);
final BGPSessionPreferences prefs = getPeerPreferences(ip);
checkPeerConfigured(ip);
final BGPSessionId currentConnection = new BGPSessionId(sourceId, remoteId, remoteAsNumber);
final BGPSessionListener p = this.peers.get(ip);
final BGPSessionId previousConnection = this.sessionIds.get(ip);
if (previousConnection != null) {
LOG.warn("Duplicate BGP session established with {}", ip);
// Session reestablished with different ids
if (!previousConnection.equals(currentConnection)) {
LOG.warn("BGP session with {} {} has to be dropped. Same session already present {}", ip, currentConnection, previousConnection);
throw new BGPDocumentedException(String.format("BGP session with %s %s has to be dropped. Same session already present %s", ip, currentConnection, previousConnection), BGPError.CEASE);
// Session reestablished with lower source bgp id, dropping current
} else if (previousConnection.isHigherDirection(currentConnection) || previousConnection.hasHigherAsNumber(currentConnection)) {
LOG.warn("BGP session with {} {} has to be dropped. Opposite session already present", ip, currentConnection);
throw new BGPDocumentedException(String.format("BGP session with %s initiated %s has to be dropped. " + "Opposite session already present", ip, currentConnection), BGPError.CEASE);
// Session reestablished with higher source bgp id, dropping previous
} else if (currentConnection.isHigherDirection(previousConnection) || currentConnection.hasHigherAsNumber(previousConnection)) {
LOG.warn("BGP session with {} {} released. Replaced by opposite session", ip, previousConnection);
this.peers.get(ip).releaseConnection();
return this.peers.get(ip);
// Session reestablished with same source bgp id, dropping current as duplicate
} else {
LOG.warn("BGP session with %s initiated from %s to %s has to be dropped. Same session already present", ip, sourceId, remoteId);
throw new BGPDocumentedException(String.format("BGP session with %s initiated %s has to be dropped. " + "Same session already present", ip, currentConnection), BGPError.CEASE);
}
}
validateAs(remoteAsNumber, openObj, prefs);
// Map session id to peer IP address
this.sessionIds.put(ip, currentConnection);
for (final PeerRegistrySessionListener peerRegistrySessionListener : this.sessionListeners) {
peerRegistrySessionListener.onSessionCreated(ip);
}
return p;
}
Aggregations