+
+ protected void initialiseExternalCounter(Routers routers, long routerId){
+ LOG.debug("NAPT Service : Initialise External IPs counter");
+ List<String> externalIps = routers.getExternalIps();
+
+ //update the new counter value for this externalIp
+ for(String externalIp : externalIps) {
+ String[] IpSplit = externalIp.split("/");
+ String extIp = IpSplit[0];
+ String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
+ if(IpSplit.length==2) {
+ extPrefix = IpSplit[1];
+ }
+ extIp = extIp + "/" + extPrefix;
+ initialiseNewExternalIpCounter(routerId, extIp);
+ }
+ }
+
+ protected void initialiseNewExternalIpCounter(long routerId, String ExternalIp){
+ ExternalIpCounter externalIpCounterData = new ExternalIpCounterBuilder().setKey(new ExternalIpCounterKey(ExternalIp)).
+ setExternalIp(ExternalIp).setCounter((short) 0).build();
+ MDSALUtil.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, getExternalIpsIdentifier(routerId, ExternalIp), externalIpCounterData);
+ }
+
+ protected void removeExternalCounter(long routerId){
+ // Remove from external-counters model
+ InstanceIdentifier<ExternalCounters> id = InstanceIdentifier.builder(ExternalIpsCounter.class).child(ExternalCounters.class, new ExternalCountersKey(routerId)).build();
+ LOG.debug("NAPT Service : Removing ExternalCounterd from datastore");
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, id);
+ }
+
+ protected void removeExternalIpCounter(long routerId, String externalIp){
+ // Remove from external-counters model
+ InstanceIdentifier<ExternalIpCounter> id = InstanceIdentifier.builder(ExternalIpsCounter.class).child(ExternalCounters.class,
+ new ExternalCountersKey(routerId)).child(ExternalIpCounter.class, new ExternalIpCounterKey(externalIp)).build();
+ LOG.debug("NAPT Service : Removing ExternalIpsCounter from datastore");
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, id);
+ }
+