- this.routerIp = InetAddresses.toAddrString(session.getRemoteAddress());
- this.routerId = new RouterId(Ipv4Util.getIpAddress(session.getRemoteAddress()));
- this.routerYangIId = YangInstanceIdentifier.builder(this.sessionManager.getRoutersYangIId()).nodeWithKey(Router.QNAME,
- ROUTER_ID_QNAME, this.routerIp).build();
- this.peersYangIId = YangInstanceIdentifier.builder(routerYangIId).node(Peer.QNAME).build();
- createRouterEntry();
- this.sessionManager.addSessionListener(this);
+ this.routerIp = InetAddresses.toAddrString(this.session.getRemoteAddress());
+ this.routerId = new RouterId(Ipv4Util.getIpAddress(this.session.getRemoteAddress()));
+ // check if this session is redundant
+ if (!this.sessionManager.addSessionListener(this)) {
+ LOG.warn("Redundant BMP session with remote router {} ({}) detected. This BMP session will be abandoned.",
+ this.routerIp, this.session);
+ this.close();
+ } else {
+ this.routerYangIId = YangInstanceIdentifier.builder(this.sessionManager.getRoutersYangIId())
+ .nodeWithKey(Router.QNAME, ROUTER_ID_QNAME, this.routerIp).build();
+ this.peersYangIId = YangInstanceIdentifier.builder(this.routerYangIId).node(Peer.QNAME).build();
+ createRouterEntry();
+ LOG.info("BMP session with remote router {} ({}) is up now.", this.routerIp, this.session);
+ }