- this.adjRibsInId = this.targetRib.getYangRibId().node(Peer.QNAME).node(peerId).node(AdjRibIn.QNAME).node(Tables.QNAME);
- this.chain = this.targetRib.createPeerChain(this);
- this.writerChain = this.targetRib.createPeerChain(this);
- this.writer = AdjRibInWriter.create(this.targetRib.getYangRibId(), PeerRole.Ibgp, this.writerChain);
- // FIXME: set to true, once it's fixed how to skip advertising routes back to AppPeer
- this.writer = this.writer.transform(RouterIds.createPeerId(ipAddress), this.targetRib.getRibSupportContext(), this.targetRib.getLocalTablesKeys(), false);
+ this.peerIId = targetRib.getYangRibId().node(Peer.QNAME).node(peerId);
+ this.adjRibsInId = this.peerIId.node(AdjRibIn.QNAME).node(Tables.QNAME);
+ this.rib = targetRib;
+ this.ipAddress = ipAddress;
+ this.moduleTracker = moduleTracker;
+ }
+
+ public ApplicationPeer(final ApplicationRibId applicationRibId, final Ipv4Address bgpPeerId, final RIB targetRibDependency) {
+ this(applicationRibId, bgpPeerId, targetRibDependency, null);
+ }
+
+ public synchronized void instantiateServiceInstance(final DOMDataTreeChangeService dataTreeChangeService,
+ final DOMDataTreeIdentifier appPeerDOMId) {
+ this.chain = this.rib.createPeerChain(this);
+ this.writerChain = this.rib.createPeerChain(this);
+
+ final Optional<SimpleRoutingPolicy> simpleRoutingPolicy = Optional.of(SimpleRoutingPolicy.AnnounceNone);
+ final PeerId peerId = RouterIds.createPeerId(this.ipAddress);
+ final Set<TablesKey> localTables = this.rib.getLocalTablesKeys();
+ localTables.forEach(tablesKey -> {
+ final ExportPolicyPeerTracker exportTracker = this.rib.getExportPolicyPeerTracker(tablesKey);
+ if (exportTracker != null) {
+ exportTracker.registerPeer(peerId, null, this.peerIId, PeerRole.Internal, simpleRoutingPolicy);
+ }
+ this.supportedTables.add(RibSupportUtils.toYangTablesKey(tablesKey));
+ });
+
+ this.adjRibInWriter = AdjRibInWriter.create(this.rib.getYangRibId(), PeerRole.Internal, simpleRoutingPolicy, this.writerChain);
+ final RIBSupportContextRegistry context = this.rib.getRibSupportContext();
+ final RegisterAppPeerListener registerAppPeerListener = () -> {
+ synchronized (this) {
+ if(this.chain != null) {
+ this.registration = dataTreeChangeService.registerDataTreeChangeListener(appPeerDOMId, this);
+ }
+ }
+ };
+ this.adjRibInWriter = this.adjRibInWriter.transform(peerId, context, localTables, Collections.emptyMap(),
+ registerAppPeerListener);
+ this.peerStats = new BGPPeerStatsImpl(this.name, localTables);
+ this.effectiveRibInWriter = EffectiveRibInWriter.create(this.rib.getService(), this.rib.createPeerChain(this), this.peerIId,
+ this.rib.getImportPolicyPeerTracker(), context, PeerRole.Internal, this.peerStats.getEffectiveRibInRouteCounters(),
+ this.peerStats.getAdjRibInRouteCounters());
+ if (moduleTracker != null) {
+ moduleTracker.onInstanceCreate();
+ }