use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.
the class NaptManager method updateCounter.
public void updateCounter(long segmentId, String externalIp, boolean isAdd) {
short counter = 0;
InstanceIdentifier<ExternalIpCounter> id = InstanceIdentifier.builder(ExternalIpsCounter.class).child(ExternalCounters.class, new ExternalCountersKey(segmentId)).child(ExternalIpCounter.class, new ExternalIpCounterKey(externalIp)).build();
Optional<ExternalIpCounter> externalIpCounter = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (externalIpCounter.isPresent()) {
counter = externalIpCounter.get().getCounter();
if (isAdd) {
counter++;
LOG.debug("updateCounter : externalIp and counter after increment are {} and {}", externalIp, counter);
} else {
if (counter > 0) {
counter--;
}
LOG.debug("updateCounter : externalIp and counter after decrement are {} and {}", externalIp, counter);
}
} else if (isAdd) {
counter = 1;
}
// update the new counter value for this externalIp
ExternalIpCounter externalIpCounterData = new ExternalIpCounterBuilder().setKey(new ExternalIpCounterKey(externalIp)).setExternalIp(externalIp).setCounter(counter).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, getExternalIpsIdentifier(segmentId, externalIp), externalIpCounterData);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.
the class NaptManager method removeFromIpMapDS.
protected void removeFromIpMapDS(long segmentId, String internalIp) {
InstanceIdentifierBuilder<IpMap> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(segmentId)).child(IpMap.class, new IpMapKey(internalIp));
InstanceIdentifier<IpMap> id = idBuilder.build();
// Get externalIp and decrement the counter
String externalIp = null;
Optional<IpMap> ipMap = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (ipMap.isPresent()) {
externalIp = ipMap.get().getExternalIp();
LOG.debug("removeFromIpMapDS : externalIP is {}", externalIp);
} else {
LOG.warn("removeFromIpMapDS : ipMap not present for the internal IP {}", internalIp);
}
if (externalIp != null) {
updateCounter(segmentId, externalIp, false);
// remove from ipmap DS
LOG.debug("removeFromIpMapDS : Removing ipmap from datastore");
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
} else {
LOG.warn("removeFromIpMapDS : externalIp not present for the internal IP {}", internalIp);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.
the class ExternalRoutersListener method subnetRegisterMapping.
protected void subnetRegisterMapping(Routers routerEntry, Long segmentId) {
List<Uuid> subnetList = null;
List<String> externalIps = null;
LOG.debug("subnetRegisterMapping : Fetching values from extRouters model");
subnetList = routerEntry.getSubnetIds();
externalIps = NatUtil.getIpsListFromExternalIps(routerEntry.getExternalIps());
int counter = 0;
int extIpCounter = externalIps.size();
LOG.debug("subnetRegisterMapping : counter values before looping counter {} and extIpCounter {}", counter, extIpCounter);
for (Uuid subnet : subnetList) {
LOG.debug("subnetRegisterMapping : Looping internal subnets for subnet {}", subnet);
InstanceIdentifier<Subnetmap> subnetmapId = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnet)).build();
Optional<Subnetmap> sn = read(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetmapId);
if (sn.isPresent()) {
// subnets
Subnetmap subnetmapEntry = sn.get();
String subnetString = subnetmapEntry.getSubnetIp();
String[] subnetSplit = subnetString.split("/");
String subnetIp = subnetSplit[0];
try {
InetAddress address = InetAddress.getByName(subnetIp);
if (address instanceof Inet6Address) {
LOG.debug("subnetRegisterMapping : Skipping ipv6 subnet {} for the router {} with ipv6 address " + "{} ", subnet, routerEntry.getRouterName(), address);
continue;
}
} catch (UnknownHostException e) {
LOG.error("subnetRegisterMapping : Invalid ip address {}", subnetIp, e);
return;
}
String subnetPrefix = "0";
if (subnetSplit.length == 2) {
subnetPrefix = subnetSplit[1];
}
IPAddress subnetAddr = new IPAddress(subnetIp, Integer.parseInt(subnetPrefix));
LOG.debug("subnetRegisterMapping : subnetAddr is {} and subnetPrefix is {}", subnetAddr.getIpAddress(), subnetAddr.getPrefixLength());
// externalIps
LOG.debug("subnetRegisterMapping : counter values counter {} and extIpCounter {}", counter, extIpCounter);
if (extIpCounter != 0) {
if (counter < extIpCounter) {
String[] ipSplit = externalIps.get(counter).split("/");
String externalIp = ipSplit[0];
String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
if (ipSplit.length == 2) {
extPrefix = ipSplit[1];
}
IPAddress externalIpAddr = new IPAddress(externalIp, Integer.parseInt(extPrefix));
LOG.debug("subnetRegisterMapping : externalIp is {} and extPrefix is {}", externalIpAddr.getIpAddress(), externalIpAddr.getPrefixLength());
naptManager.registerMapping(segmentId, subnetAddr, externalIpAddr);
LOG.debug("subnetRegisterMapping : Called registerMapping for subnetIp {}, prefix {}, " + "externalIp {}. prefix {}", subnetIp, subnetPrefix, externalIp, extPrefix);
} else {
// Reset the counter which runs on externalIps for round-robbin effect
counter = 0;
LOG.debug("subnetRegisterMapping : Counter on externalIps got reset");
String[] ipSplit = externalIps.get(counter).split("/");
String externalIp = ipSplit[0];
String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
if (ipSplit.length == 2) {
extPrefix = ipSplit[1];
}
IPAddress externalIpAddr = new IPAddress(externalIp, Integer.parseInt(extPrefix));
LOG.debug("subnetRegisterMapping : externalIp is {} and extPrefix is {}", externalIpAddr.getIpAddress(), externalIpAddr.getPrefixLength());
naptManager.registerMapping(segmentId, subnetAddr, externalIpAddr);
LOG.debug("subnetRegisterMapping : Called registerMapping for subnetIp {}, prefix {}, " + "externalIp {}. prefix {}", subnetIp, subnetPrefix, externalIp, extPrefix);
}
}
counter++;
LOG.debug("subnetRegisterMapping : Counter on externalIps incremented to {}", counter);
} else {
LOG.warn("subnetRegisterMapping : No internal subnets present in extRouters Model");
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.
the class NaptManager method initialiseExternalCounter.
protected void initialiseExternalCounter(Routers routers, long routerId) {
LOG.debug("initialiseExternalCounter : Initialise External IPs counter");
List<ExternalIps> externalIps = routers.getExternalIps();
// update the new counter value for this externalIp
for (ExternalIps externalIp : externalIps) {
String[] ipSplit = externalIp.getIpAddress().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);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project openflowplugin by opendaylight.
the class TableFeaturesConvertorTest method getTableProperties.
private static TableProperties getTableProperties() {
TableFeaturePropertiesBuilder tableFeaturePropertiesBuilder = new TableFeaturePropertiesBuilder();
List<TableFeatureProperties> tableFeaturePropertieses = new ArrayList<>();
int counter = 0;
for (Entry<Class<? extends TableFeaturePropType>, TableFeaturePropType> entry : AUGMENTATIONS_MAP.entrySet()) {
counter++;
tableFeaturePropertiesBuilder.setTableFeaturePropType(entry.getValue());
tableFeaturePropertiesBuilder.setOrder(counter);
tableFeaturePropertieses.add(tableFeaturePropertiesBuilder.build());
}
tableFeaturePropertieses.add(tableFeaturePropertiesBuilder.build());
TABLE_PROPERTIES_BUILDER.setTableFeatureProperties(tableFeaturePropertieses);
return TABLE_PROPERTIES_BUILDER.build();
}
Aggregations