+ public synchronized void
+ addLogging(String fileName, String logLevel) {
+ InstanceIdentifier.InstanceIdentifierBuilder<Logging> iib =
+ InstanceIdentifier.builder(Bgp.class).child(Logging.class);
+ InstanceIdentifier<Logging> iid = iib.build();
+ Logging dto = new LoggingBuilder().setFile(fileName)
+ .setLevel(logLevel).build();
+ update(iid, dto);
+ }
+
+ public synchronized void
+ addGracefulRestart(int staleTime) {
+ InstanceIdentifier.InstanceIdentifierBuilder<GracefulRestart> iib =
+ InstanceIdentifier.builder(Bgp.class).child(GracefulRestart.class);
+ InstanceIdentifier<GracefulRestart> iid = iib.build();
+ GracefulRestart dto = new GracefulRestartBuilder()
+ .setStalepathTime((long)staleTime).build();
+ update(iid, dto);
+ }
+
+ public synchronized void
+ addNeighbor(String nbrIp, int remoteAs) {
+ Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
+ Long rAs = (long) remoteAs;
+ InstanceIdentifier.InstanceIdentifierBuilder<Neighbors> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(Neighbors.class, new NeighborsKey(nbrAddr));
+ InstanceIdentifier<Neighbors> iid = iib.build();
+ Neighbors dto = new NeighborsBuilder().setAddress(nbrAddr)
+ .setRemoteAs(rAs).build();
+ update(iid, dto);
+ }
+
+ public synchronized void
+ addUpdateSource(String nbrIp, String srcIp) {
+ Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
+ Ipv4Address srcAddr = new Ipv4Address(srcIp);
+ InstanceIdentifier.InstanceIdentifierBuilder<UpdateSource> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(Neighbors.class, new NeighborsKey(nbrAddr))
+ .child(UpdateSource.class);
+ InstanceIdentifier<UpdateSource> iid = iib.build();
+ UpdateSource dto = new UpdateSourceBuilder().setPeerIp(nbrAddr)
+ .setSourceIp(srcAddr).build();
+ update(iid, dto);
+ }
+
+ public synchronized void
+ addEbgpMultihop(String nbrIp, int nHops) {
+ Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
+ InstanceIdentifier.InstanceIdentifierBuilder<EbgpMultihop> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(Neighbors.class, new NeighborsKey(nbrAddr))
+ .child(EbgpMultihop.class);
+ InstanceIdentifier<EbgpMultihop> iid = iib.build();
+ EbgpMultihop dto = new EbgpMultihopBuilder().setPeerIp(nbrAddr)
+ .setNhops((long)nHops).build();
+ update(iid, dto);
+ }
+
+ public synchronized void
+ addAddressFamily(String nbrIp, int afi, int safi) {
+ Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
+ Long a = (long) afi;
+ Long sa = (long) safi;
+ InstanceIdentifier.InstanceIdentifierBuilder<AddressFamilies> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(Neighbors.class, new NeighborsKey(nbrAddr))
+ .child(AddressFamilies.class, new AddressFamiliesKey(a, sa));
+ InstanceIdentifier<AddressFamilies> iid = iib.build();
+ AddressFamilies dto = new AddressFamiliesBuilder().setPeerIp(nbrAddr)
+ .setAfi(a).setSafi(sa).build();
+ update(iid, dto);
+ }
+
+ public synchronized void
+ addPrefix(String rd, String pfx, String nh, int lbl) {
+ Ipv4Address nexthop = new Ipv4Address(nh);
+ Long label = (long) lbl;
+ InstanceIdentifier.InstanceIdentifierBuilder<Networks> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(Networks.class, new NetworksKey(pfx, rd));
+ InstanceIdentifier<Networks> iid = iib.build();
+ Networks dto = new NetworksBuilder().setRd(rd)
+ .setPrefixLen(pfx)
+ .setNexthop(nexthop)
+ .setLabel(label).build();
+ update(iid, dto);
+ }
+
+ public synchronized void
+ addVrf(String rd, List<String> irts, List<String> erts) {
+ InstanceIdentifier.InstanceIdentifierBuilder<Vrfs> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(Vrfs.class, new VrfsKey(rd));
+ InstanceIdentifier<Vrfs> iid = iib.build();
+ Vrfs dto = new VrfsBuilder().setRd(rd)
+ .setImportRts(irts)
+ .setExportRts(erts).build();
+
+ asyncWrite(iid, dto);
+ }
+
+ public synchronized void stopConfig() {
+ InstanceIdentifier.InstanceIdentifierBuilder<ConfigServer> iib =
+ InstanceIdentifier.builder(Bgp.class).child(ConfigServer.class);
+ InstanceIdentifier<ConfigServer> iid = iib.build();
+ delete(iid);
+ }
+
+ public synchronized void stopBgp() {
+ InstanceIdentifier.InstanceIdentifierBuilder<AsId> iib =
+ InstanceIdentifier.builder(Bgp.class).child(AsId.class);
+ InstanceIdentifier<AsId> iid = iib.build();
+ delete(iid);
+ }
+
+ public synchronized void delLogging() {
+ InstanceIdentifier.InstanceIdentifierBuilder<Logging> iib =
+ InstanceIdentifier.builder(Bgp.class).child(Logging.class);
+ InstanceIdentifier<Logging> iid = iib.build();
+ delete(iid);
+ }
+
+ public synchronized void delGracefulRestart() {
+ InstanceIdentifier.InstanceIdentifierBuilder<GracefulRestart> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(GracefulRestart.class);
+ InstanceIdentifier<GracefulRestart> iid = iib.build();
+ delete(iid);
+ }
+
+ public synchronized void delNeighbor(String nbrIp) {
+ Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
+ InstanceIdentifier.InstanceIdentifierBuilder<Neighbors> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(Neighbors.class, new NeighborsKey(nbrAddr));
+ InstanceIdentifier<Neighbors> iid = iib.build();
+ delete(iid);
+ }
+
+ public synchronized void delUpdateSource(String nbrIp) {
+ Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
+ InstanceIdentifier.InstanceIdentifierBuilder<UpdateSource> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(Neighbors.class, new NeighborsKey(nbrAddr))
+ .child(UpdateSource.class);
+ InstanceIdentifier<UpdateSource> iid = iib.build();
+ delete(iid);
+ }
+
+ public synchronized void delEbgpMultihop(String nbrIp) {
+ Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
+ InstanceIdentifier.InstanceIdentifierBuilder<EbgpMultihop> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(Neighbors.class, new NeighborsKey(nbrAddr))
+ .child(EbgpMultihop.class);
+ InstanceIdentifier<EbgpMultihop> iid = iib.build();
+ delete(iid);
+ }
+
+ public synchronized void
+ delAddressFamily(String nbrIp, int afi, int safi) {
+ Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
+ Long a = (long) afi;
+ Long sa = (long) safi;
+ InstanceIdentifier.InstanceIdentifierBuilder<AddressFamilies> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(Neighbors.class, new NeighborsKey(nbrAddr))
+ .child(AddressFamilies.class, new AddressFamiliesKey(a, sa));
+ InstanceIdentifier<AddressFamilies> iid = iib.build();
+ delete(iid);
+ }
+
+ public synchronized void delPrefix(String rd, String pfx) {
+ InstanceIdentifier.InstanceIdentifierBuilder<Networks> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(Networks.class, new NetworksKey(pfx, rd));
+ InstanceIdentifier<Networks> iid = iib.build();
+ delete(iid);
+ }
+
+ public synchronized void delVrf(String rd) {
+ InstanceIdentifier.InstanceIdentifierBuilder<Vrfs> iib =
+ InstanceIdentifier.builder(Bgp.class)
+ .child(Vrfs.class, new VrfsKey(rd));
+ InstanceIdentifier<Vrfs> iid = iib.build();
+ delete(iid);
+ }
+
+ static ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
+ /*
+ * Remove Stale Marked Routes after timer expiry.
+ */
+ class RouteCleanup implements Callable<Integer> {
+
+ public Integer call () {
+ int totalCleared = 0;