import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
import org.opendaylight.genius.mdsalutil.InstructionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ExternalNetworkListener extends AbstractDataChangeListener<Networks> implements AutoCloseable {
+public class ExternalNetworkListener extends AsyncDataTreeChangeListenerBase<Networks, ExternalNetworkListener> implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(ExternalNetworkListener.class);
- private ListenerRegistration<DataChangeListener> listenerRegistration;
private final DataBroker dataBroker;
private final IMdsalApiManager mdsalManager;
public ExternalNetworkListener (final DataBroker dataBroker, final IMdsalApiManager mdsalManager) {
- super(Networks.class);
+ super(Networks.class, ExternalNetworkListener.class);
this.dataBroker = dataBroker;
this.mdsalManager = mdsalManager;
}
+ @Override
public void init() {
LOG.info("{} init", getClass().getSimpleName());
- listenerRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
- getWildCardPath(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
+ registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
}
- private InstanceIdentifier<Networks> getWildCardPath() {
- return InstanceIdentifier.create(ExternalNetworks.class).child(Networks.class);
+ @Override
+ protected ExternalNetworkListener getDataTreeChangeListener() {
+ return ExternalNetworkListener.this;
}
@Override
- public void close() throws Exception {
- if (listenerRegistration != null) {
- listenerRegistration.close();
- listenerRegistration = null;
- }
- LOG.info("{} close", getClass().getSimpleName());
+ protected InstanceIdentifier<Networks> getWildCardPath() {
+ return InstanceIdentifier.create(ExternalNetworks.class).child(Networks.class);
}
@Override
protected void add(final InstanceIdentifier<Networks> identifier,
final Networks nw) {
- LOG.trace("External Network add mapping method - key: " + identifier + ", value=" + nw );
+ LOG.trace("NAT Service : External Network add mapping method - key: " + identifier + ", value=" + nw );
processExternalNwAdd(identifier, nw);
}
@Override
protected void remove(InstanceIdentifier<Networks> identifier, Networks nw) {
- LOG.trace("External Network remove mapping method - key: " + identifier + ", value=" + nw );
+ LOG.trace("NAT Service : External Network remove mapping method - key: " + identifier + ", value=" + nw );
processExternalNwDel(identifier, nw);
}
@Override
protected void update(InstanceIdentifier<Networks> identifier, Networks original, Networks update) {
- LOG.trace("External Network update mapping method - key: " + identifier + ", original=" + original + ", update=" + update );
+ LOG.trace("NAT Service : External Network update mapping method - key: " + identifier + ", original=" + original + ", update=" + update );
//check if a new router has been added or an already existing router has been deleted from the external nw to router association
List<Uuid> oldRtrs = original.getRouterIds();
List<Uuid> newRtrs = update.getRouterIds();
private void processExternalNwAdd(final InstanceIdentifier<Networks> identifier,
final Networks network) {
- LOG.trace("Add event - key: {}, value: {}", identifier, network);
+ LOG.trace("NAT Service : Add event - key: {}, value: {}", identifier, network);
List<Uuid> routerList = network.getRouterIds();
if(routerList == null) {
private void processExternalNwDel(final InstanceIdentifier<Networks> identifier,
final Networks network) {
- LOG.trace("Add event - key: {}, value: {}", identifier, network);
+ LOG.trace("NAT Service : Add event - key: {}, value: {}", identifier, network);
List<Uuid> routerList = network.getRouterIds();
for(Uuid router: routerList) {
defaultIP = InetAddress.getByName("0.0.0.0");
} catch (UnknownHostException e) {
- LOG.error("UnknowHostException in buildDefNATFlowEntity. Failed to build FIB Table Flow for Default Route to NAT table ");
+ LOG.error("NAT Service : UnknowHostException in buildDefNATFlowEntity. Failed to build FIB Table Flow for Default Route to NAT table ");
return null;
}
private void installDefNATRouteInDPN(BigInteger dpnId, long vpnId) {
FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, vpnId);
if(flowEntity == null) {
- LOG.error("Flow entity received is NULL. Cannot proceed with installation of Default NAT flow");
+ LOG.error("NAT Service : Flow entity received is NULL. Cannot proceed with installation of Default NAT flow");
return;
}
mdsalManager.installFlow(flowEntity);
private void removeDefNATRouteInDPN(BigInteger dpnId, long vpnId) {
FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, vpnId);
if(flowEntity == null) {
- LOG.error("Flow entity received is NULL. Cannot proceed with installation of Default NAT flow");
+ LOG.error("NAT Service : Flow entity received is NULL. Cannot proceed with installation of Default NAT flow");
return;
}
mdsalManager.removeFlow(flowEntity);
import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.genius.mdsalutil.ActionInfo;
import org.opendaylight.genius.mdsalutil.ActionType;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
-
import com.google.common.base.Optional;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
-public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> implements AutoCloseable{
+public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<IpMapping, FloatingIPListener> implements AutoCloseable{
private static final Logger LOG = LoggerFactory.getLogger(FloatingIPListener.class);
- private ListenerRegistration<DataChangeListener> listenerRegistration;
private final DataBroker dataBroker;
private final IMdsalApiManager mdsalManager;
private final OdlInterfaceRpcService interfaceManager;
final OdlInterfaceRpcService interfaceManager,
final IdManagerService idManager,
final BundleContext bundleContext) {
- super(IpMapping.class);
+ super(IpMapping.class, FloatingIPListener.class);
this.dataBroker = dataBroker;
this.mdsalManager = mdsalManager;
this.interfaceManager = interfaceManager;
this.idManager = idManager;
-
GlobalEventExecutor.INSTANCE.execute(new Runnable() {
@Override
public void run() {
public void init() {
LOG.info("{} init", getClass().getSimpleName());
- listenerRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
- getWildCardPath(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
+ registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
}
- private InstanceIdentifier<IpMapping> getWildCardPath() {
- return InstanceIdentifier.create(FloatingIpInfo.class).child(RouterPorts.class).child(Ports.class)
- .child(IpMapping.class);
+ @Override
+ protected InstanceIdentifier<IpMapping> getWildCardPath() {
+ return InstanceIdentifier.create(FloatingIpInfo.class).child(RouterPorts.class).child(Ports.class).child(IpMapping.class);
}
@Override
- public void close() throws Exception {
- if (listenerRegistration != null) {
- listenerRegistration.close();
- listenerRegistration = null;
- }
- LOG.info("{} close", getClass().getSimpleName());
+ protected FloatingIPListener getDataTreeChangeListener() {
+ return FloatingIPListener.this;
}
-
@Override
protected void add(final InstanceIdentifier<IpMapping> identifier,
final IpMapping mapping) {
- LOG.trace("FloatingIPListener add ip mapping method - key: " + identifier + ", value=" + mapping );
+ LOG.trace("NAT Service : FloatingIPListener add ip mapping method - key: " + identifier + ", value=" + mapping );
processFloatingIPAdd(identifier, mapping);
}
@Override
protected void remove(InstanceIdentifier<IpMapping> identifier, IpMapping mapping) {
- LOG.trace("FloatingIPListener remove ip mapping method - key: " + identifier + ", value=" + mapping );
+ LOG.trace("NAT Service : FloatingIPListener remove ip mapping method - key: " + identifier + ", value=" + mapping );
processFloatingIPDel(identifier, mapping);
}
}
private FlowEntity buildPreDNATFlowEntity(BigInteger dpId, String internalIp, String externalIp, long routerId, long vpnId, long associatedVpn) {
- LOG.info("Bulding DNAT Flow entity for ip {} ", externalIp);
+ LOG.info("NAT Service : Bulding DNAT Flow entity for ip {} ", externalIp);
long segmentId = (associatedVpn == NatConstants.INVALID_ID) ? routerId : associatedVpn;
- LOG.debug("Segment id {} in build preDNAT Flow", segmentId);
+ LOG.debug("NAT Service : Segment id {} in build preDNAT Flow", segmentId);
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchInfo(MatchFieldType.eth_type,
private FlowEntity buildDNATFlowEntity(BigInteger dpId, String internalIp, String externalIp, long routerId, long associatedVpn) {
- LOG.info("Bulding DNAT Flow entity for ip {} ", externalIp);
+ LOG.info("NAT Service : Bulding DNAT Flow entity for ip {} ", externalIp);
long segmentId = (associatedVpn == NatConstants.INVALID_ID) ? routerId : associatedVpn;
- LOG.debug("Segment id {} in build DNAT", segmentId);
+ LOG.debug("NAT Service : Segment id {} in build DNAT", segmentId);
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchInfo(MatchFieldType.metadata, new BigInteger[] {
private FlowEntity buildPreSNATFlowEntity(BigInteger dpId, String internalIp, String externalIp, long vpnId, long routerId, long associatedVpn) {
- LOG.info("Building PSNAT Flow entity for ip {} ", internalIp);
+ LOG.info("NAT Service : Building PSNAT Flow entity for ip {} ", internalIp);
long segmentId = (associatedVpn == NatConstants.INVALID_ID) ? routerId : associatedVpn;
- LOG.debug("Segment id {} in build preSNAT flow", segmentId);
+ LOG.debug("NAT Service : Segment id {} in build preSNAT flow", segmentId);
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchInfo(MatchFieldType.eth_type,
private Uuid getExtNetworkId(final InstanceIdentifier<RouterPorts> pIdentifier, LogicalDatastoreType dataStoreType) {
Optional<RouterPorts> rtrPort = NatUtil.read(dataBroker, dataStoreType, pIdentifier);
if(!rtrPort.isPresent()) {
- LOG.error("Unable to read router port entry for {}", pIdentifier);
+ LOG.error("NAT Service : Unable to read router port entry for {}", pIdentifier);
return null;
}
InstanceIdentifier<Networks> nwId = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNwId)).build();
Optional<Networks> nw = NatUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, nwId);
if(!nw.isPresent()) {
- LOG.error("Unable to read external network for {}", extNwId);
+ LOG.error("NAT Service : Unable to read external network for {}", extNwId);
return NatConstants.INVALID_ID;
}
private void processFloatingIPAdd(final InstanceIdentifier<IpMapping> identifier,
final IpMapping mapping) {
- LOG.trace("Add event - key: {}, value: {}", identifier, mapping);
+ LOG.trace("NAT Service : Add event - key: {}, value: {}", identifier, mapping);
final String routerId = identifier.firstKeyOf(RouterPorts.class).getRouterId();
final PortsKey pKey = identifier.firstKeyOf(Ports.class);
private void processFloatingIPDel(final InstanceIdentifier<IpMapping> identifier,
final IpMapping mapping) {
- LOG.trace("Del event - key: {}, value: {}", identifier, mapping);
+ LOG.trace("NAT Service : Del event - key: {}, value: {}", identifier, mapping);
final String routerId = identifier.firstKeyOf(RouterPorts.class).getRouterId();
final PortsKey pKey = identifier.firstKeyOf(Ports.class);
try {
ipAddress = InetAddress.getByName(ipAddr);
} catch (UnknownHostException e) {
- LOG.error("UnknowHostException for ip {}", ipAddr);
+ LOG.error("NAT Service : UnknowHostException for ip {}", ipAddr);
}
return ipAddress;
}
void createNATFlowEntries(String interfaceName, final IpMapping mapping,
final InstanceIdentifier<RouterPorts> pIdentifier, final String routerName) {
if(!validateIpMapping(mapping)) {
- LOG.warn("Not a valid ip addresses in the mapping {}", mapping);
+ LOG.warn("NAT Service : Not a valid ip addresses in the mapping {}", mapping);
return;
}
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, interfaceName);
if(dpnId.equals(BigInteger.ZERO)) {
- LOG.error("No DPN for interface {}. NAT flow entries for ip mapping {} will not be installed",
+ LOG.error("NAT Service : No DPN for interface {}. NAT flow entries for ip mapping {} will not be installed",
interfaceName, mapping);
return;
}
long routerId = NatUtil.getVpnId(dataBroker, routerName);
if(routerId == NatConstants.INVALID_ID) {
- LOG.warn("Could not retrieve router id for {} to create NAT Flow entries", routerName);
+ LOG.warn("NAT Service : Could not retrieve router id for {} to create NAT Flow entries", routerName);
return;
}
//Check if the router to vpn association is present
Uuid associatedVpn = NatUtil.getVpnForRouter(dataBroker, routerName);
long associatedVpnId = NatConstants.INVALID_ID;
if(associatedVpn == null) {
- LOG.debug("Router {} is not assicated with any BGP VPN instance", routerName);
+ LOG.debug("NAT Service : Router {} is not assicated with any BGP VPN instance", routerName);
} else {
- LOG.debug("Router {} is associated with VPN Instance with Id {}", routerName, associatedVpn);
+ LOG.debug("NAT Service : Router {} is associated with VPN Instance with Id {}", routerName, associatedVpn);
associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVpn.getValue());
- LOG.debug("vpninstance Id is {} for VPN {}", associatedVpnId, associatedVpn);
+ LOG.debug("NAT Service : vpninstance Id is {} for VPN {}", associatedVpnId, associatedVpn);
//routerId = associatedVpnId;
}
Uuid extNwId = getExtNetworkId(pIdentifier, LogicalDatastoreType.CONFIGURATION);
if(extNwId == null) {
- LOG.error("External network associated with interface {} could not be retrieved", interfaceName);
- LOG.error("NAT flow entries will not be installed {}", mapping);
+ LOG.error("NAT Service : External network associated with interface {} could not be retrieved", interfaceName);
+ LOG.error("NAT Service : NAT flow entries will not be installed {}", mapping);
return;
}
long vpnId = getVpnId(extNwId);
if(vpnId < 0) {
- LOG.error("No VPN associated with Ext nw {}. Unable to create SNAT table entry for fixed ip {}",
+ LOG.error("NAT Service : No VPN associated with Ext nw {}. Unable to create SNAT table entry for fixed ip {}",
extNwId, mapping.getInternalIp());
return;
}
void createNATFlowEntries(BigInteger dpnId, String interfaceName, String routerName, Uuid externalNetworkId, String internalIp, String externalIp) {
long routerId = NatUtil.getVpnId(dataBroker, routerName);
if(routerId == NatConstants.INVALID_ID) {
- LOG.warn("Could not retrieve router id for {} to create NAT Flow entries", routerName);
+ LOG.warn("NAT Service : Could not retrieve router id for {} to create NAT Flow entries", routerName);
return;
}
//Check if the router to vpn association is present
long associatedVpnId = NatUtil.getAssociatedVpn(dataBroker, routerName);
if(associatedVpnId == NatConstants.INVALID_ID) {
- LOG.debug("Router {} is not assicated with any BGP VPN instance", routerName);
+ LOG.debug("NAT Service : Router {} is not assicated with any BGP VPN instance", routerName);
} else {
- LOG.debug("Router {} is associated with VPN Instance with Id {}", routerName, associatedVpnId);
+ LOG.debug("NAT Service : Router {} is associated with VPN Instance with Id {}", routerName, associatedVpnId);
//routerId = associatedVpnId;
}
long vpnId = getVpnId(externalNetworkId);
if(vpnId < 0) {
- LOG.error("Unable to create SNAT table entry for fixed ip {}", internalIp);
+ LOG.error("NAT Service : Unable to create SNAT table entry for fixed ip {}", internalIp);
return;
}
//Create the DNAT and SNAT table entries
void createNATOnlyFlowEntries(BigInteger dpnId, String interfaceName, String routerName, String associatedVPN, Uuid externalNetworkId, String internalIp, String externalIp) {
//String segmentId = associatedVPN == null ? routerName : associatedVPN;
- LOG.debug("Retrieving vpn id for VPN {} to proceed with create NAT Flows", routerName);
+ LOG.debug("NAT Service : Retrieving vpn id for VPN {} to proceed with create NAT Flows", routerName);
long routerId = NatUtil.getVpnId(dataBroker, routerName);
if(routerId == NatConstants.INVALID_ID) {
LOG.warn("Could not retrieve vpn id for {} to create NAT Flow entries", routerName);
return;
}
long associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVPN);
- LOG.debug("Associated VPN Id {} for router {}", associatedVpnId, routerName);
+ LOG.debug("NAT Service : Associated VPN Id {} for router {}", associatedVpnId, routerName);
long vpnId = getVpnId(externalNetworkId);
if(vpnId < 0) {
- LOG.error("Unable to create SNAT table entry for fixed ip {}", internalIp);
+ LOG.error("NAT Service : Unable to create SNAT table entry for fixed ip {}", internalIp);
return;
}
//Create the DNAT and SNAT table entries
//Get the DPN on which this interface resides
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, interfaceName);
if(dpnId.equals(BigInteger.ZERO)) {
- LOG.info("Abort processing Floating ip configuration. No DPN for port : {}", interfaceName);
+ LOG.info("NAT Service : Abort processing Floating ip configuration. No DPN for port : {}", interfaceName);
return;
}
long routerId = NatUtil.getVpnId(dataBroker, routerName);
if(routerId == NatConstants.INVALID_ID) {
- LOG.warn("Could not retrieve router id for {} to remove NAT Flow entries", routerName);
+ LOG.warn("NAT Service : Could not retrieve router id for {} to remove NAT Flow entries", routerName);
return;
}
//if(routerId == NatConstants.INVALID_ID) {
Uuid associatedVPN = NatUtil.getVpnForRouter(dataBroker, routerName);
long associatedVpnId = NatConstants.INVALID_ID;
if(associatedVPN == null) {
- LOG.warn("Could not retrieve router id for {} to remove NAT Flow entries", routerName);
+ LOG.warn("NAT Service : Could not retrieve router id for {} to remove NAT Flow entries", routerName);
} else {
- LOG.debug("Retrieving vpn id for VPN {} to proceed with remove NAT Flows", associatedVPN.getValue());
+ LOG.debug("NAT Service : Retrieving vpn id for VPN {} to proceed with remove NAT Flows", associatedVPN.getValue());
associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVPN.getValue());
}
Uuid extNwId = getExtNetworkId(pIdentifier, LogicalDatastoreType.OPERATIONAL);
if(extNwId == null) {
- LOG.error("External network associated with interface {} could not be retrieved", interfaceName);
+ LOG.error("NAT Service : External network associated with interface {} could not be retrieved", interfaceName);
return;
}
long vpnId = getVpnId(extNwId);
if(vpnId < 0) {
- LOG.error("No VPN associated with ext nw {}. Unable to delete SNAT table entry for fixed ip {}",
+ LOG.error("NAT Service : No VPN associated with ext nw {}. Unable to delete SNAT table entry for fixed ip {}",
extNwId, mapping.getInternalIp());
return;
}
long label = getOperationalIpMapping(routerName, interfaceName, mapping.getInternalIp());
if(label < 0) {
- LOG.error("Could not retrieve label for prefix {} in router {}", mapping.getInternalIp(), routerId);
+ LOG.error("NAT Service : Could not retrieve label for prefix {} in router {}", mapping.getInternalIp(), routerId);
return;
}
//Uuid extNwId = getExtNetworkId(pIdentifier);
void removeNATFlowEntries(BigInteger dpnId, String interfaceName, String vpnName, String routerName, Uuid externalNetworkId, String internalIp, String externalIp) {
long routerId = NatUtil.getVpnId(dataBroker, routerName);
if(routerId == NatConstants.INVALID_ID) {
- LOG.warn("Could not retrieve router id for {} to remove NAT Flow entries", routerName);
+ LOG.warn("NAT Service : Could not retrieve router id for {} to remove NAT Flow entries", routerName);
return;
}
long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
if(vpnId == NatConstants.INVALID_ID) {
- LOG.warn("VPN Id not found for {} to remove NAT flow entries {}", vpnName, internalIp);
+ LOG.warn("NAT Service : VPN Id not found for {} to remove NAT flow entries {}", vpnName, internalIp);
}
//Delete the DNAT and SNAT table entries
long label = getOperationalIpMapping(routerName, interfaceName, internalIp);
if(label < 0) {
- LOG.error("Could not retrieve label for prefix {} in router {}", internalIp, routerId);
+ LOG.error("NAT Service : Could not retrieve label for prefix {} in router {}", internalIp, routerId);
return;
}
//floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, externalNetworkId, externalIp, internalIp, (int)label);
void removeNATOnlyFlowEntries(BigInteger dpnId, String interfaceName, String routerName, String associatedVPN,
String internalIp, String externalIp) {
String segmentId = associatedVPN == null ? routerName : associatedVPN;
- LOG.debug("Retrieving vpn id for VPN {} to proceed with remove NAT Flows", segmentId);
+ LOG.debug("NAT Service : Retrieving vpn id for VPN {} to proceed with remove NAT Flows", segmentId);
long routerId = NatUtil.getVpnId(dataBroker, segmentId);
if(routerId == NatConstants.INVALID_ID) {
- LOG.warn("Could not retrieve vpn id for {} to remove NAT Flow entries", segmentId);
+ LOG.warn("NAT Service : Could not retrieve vpn id for {} to remove NAT Flow entries", segmentId);
return;
}
//Delete the DNAT and SNAT table entries
void updateOperationalDS(String routerId, String interfaceName, long label, String internalIp, String externalIp) {
- LOG.info("Updating operational DS for floating ip config : {} with label {}", internalIp, label);
+ LOG.info("NAT Service : Updating operational DS for floating ip config : {} with label {}", internalIp, label);
InstanceIdentifier<Ports> portsId = NatUtil.getPortsIdentifier(routerId, interfaceName);
Optional<Ports> optPorts = NatUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, portsId);
IpMapping ipMapping = new IpMappingBuilder().setKey(new IpMappingKey(internalIp)).setInternalIp(internalIp)
.setExternalIp(externalIp).setLabel(label).build();
if(optPorts.isPresent()) {
- LOG.debug("Ports {} entry already present. Updating ipmapping for internal ip {}", interfaceName, internalIp);
+ LOG.debug("NAT Service : Ports {} entry already present. Updating ipmapping for internal ip {}", interfaceName, internalIp);
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, portsId.child(IpMapping.class, new IpMappingKey(internalIp)), ipMapping);
} else {
- LOG.debug("Adding Ports entry {} along with ipmapping {}", interfaceName, internalIp);
+ LOG.debug("NAT Service : Adding Ports entry {} along with ipmapping {}", interfaceName, internalIp);
List<IpMapping> ipMappings = new ArrayList<>();
ipMappings.add(ipMapping);
Ports ports = new PortsBuilder().setKey(new PortsKey(interfaceName)).setPortName(interfaceName).setIpMapping(ipMappings).build();
private FlowEntity buildPreDNATDeleteFlowEntity(BigInteger dpId, String internalIp, String externalIp, long routerId) {
- LOG.info("Bulding Delete DNAT Flow entity for ip {} ", externalIp);
+ LOG.info("NAT Service : Bulding Delete DNAT Flow entity for ip {} ", externalIp);
String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PDNAT_TABLE, routerId, externalIp);
private FlowEntity buildDNATDeleteFlowEntity(BigInteger dpId, String internalIp, String externalIp, long routerId) {
- LOG.info("Bulding Delete DNAT Flow entity for ip {} ", externalIp);
+ LOG.info("NAT Service : Bulding Delete DNAT Flow entity for ip {} ", externalIp);
String flowRef = NatUtil.getFlowRef(dpId, NwConstants.DNAT_TABLE, routerId, externalIp);
private FlowEntity buildPreSNATDeleteFlowEntity(BigInteger dpId, String internalIp, long routerId, String externalIp) {
- LOG.info("Building Delete PSNAT Flow entity for ip {} ", internalIp);
+ LOG.info("NAT Service : Building Delete PSNAT Flow entity for ip {} ", internalIp);
String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PSNAT_TABLE, routerId, internalIp);
private FlowEntity buildSNATDeleteFlowEntity(BigInteger dpId, String internalIp, long routerId, String externalIp) {
- LOG.info("Building Delete SNAT Flow entity for ip {} ", internalIp);
+ LOG.info("NAT Service : Building Delete SNAT Flow entity for ip {} ", internalIp);
String flowRef = NatUtil.getFlowRef(dpId, NwConstants.SNAT_TABLE, routerId, internalIp);
import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.genius.mdsalutil.BucketInfo;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import com.google.common.base.Optional;
import java.math.BigInteger;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
-public class InterfaceStateEventListener extends AbstractDataChangeListener<Interface> implements AutoCloseable {
+public class InterfaceStateEventListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceStateEventListener> implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(InterfaceStateEventListener.class);
private ListenerRegistration<DataChangeListener> listenerRegistration;
private final DataBroker dataBroker;
final NaptManager naptManager,
final NeutronvpnService neutronvpnService,
final NaptSwitchHA naptSwitchHA){
- super(Interface.class);
+ super(Interface.class, InterfaceStateEventListener.class);
this.dataBroker = dataBroker;
this.mdsalManager = mdsalManager;
this.floatingIPListener = floatingIPListener;
public void init() {
LOG.info("{} init", getClass().getSimpleName());
- listenerRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- getWildCardPath(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
+ registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
}
- private InstanceIdentifier<Interface> getWildCardPath() {
+ @Override
+ protected InstanceIdentifier<Interface> getWildCardPath() {
return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
}
@Override
- public void close() throws Exception {
- if (listenerRegistration != null) {
- listenerRegistration.close();
- listenerRegistration = null;
- }
- LOG.info("{} close", getClass().getSimpleName());
+ protected InterfaceStateEventListener getDataTreeChangeListener() {
+ return InterfaceStateEventListener.this;
}
@Override
IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId,
internalIp, String.valueOf(portnum), proto);
if (ipPortExternal == null) {
- LOG.error("Mapping for internalIp {} with port {} is not found in router with Id {}",internalIp,portnum,routerId);
+ LOG.error("NAT Service : Mapping for internalIp {} with port {} is not found in router with Id {}",internalIp,portnum,routerId);
return;
}
String externalIpAddress = ipPortExternal.getIpAddress();
interfaceName, routerName);
}
} else {
- LOG.debug("Router is not associated to vpnname {} for interface {}",vpnName,interfaceName);
+ LOG.debug("NAT Service : Router is not associated to vpnname {} for interface {}",vpnName,interfaceName);
}
} else {
LOG.debug("NAT Service : vpnName not found for vpnInterface {} of port {}",vpnInterface,interfaceName);
}
private void processInterfaceAdded(String portName, String rtrId) {
- LOG.trace("Processing Interface Add Event for interface {}", portName);
+ LOG.trace("NAT Service : Processing Interface Add Event for interface {}", portName);
String routerId = getRouterIdForPort(dataBroker, portName);
List<IpMapping> ipMappingList = getIpMappingForPortName(portName, routerId);
if (ipMappingList == null || ipMappingList.isEmpty()) {
- LOG.trace("Ip Mapping list is empty/null for portname {}", portName);
+ LOG.trace("NAT Service : Ip Mapping list is empty/null for portname {}", portName);
return;
}
InstanceIdentifier<RouterPorts> pIdentifier = NatUtil.buildRouterPortsIdentifier(routerId);
String routerId = getRouterIdForPort(dataBroker, portName);
List<IpMapping> ipMappingList = getIpMappingForPortName(portName, routerId);
if (ipMappingList == null || ipMappingList.isEmpty()) {
- LOG.trace("Ip Mapping list is empty/null for portName {}", portName);
+ LOG.trace("NAT Service : Ip Mapping list is empty/null for portName {}", portName);
return;
}
InstanceIdentifier<RouterPorts> pIdentifier = NatUtil.buildRouterPortsIdentifier(routerId);
}
private List<String> getFixedIpsForPort (String interfname) {
- LOG.debug("getFixedIpsForPort method is called for interface {}",interfname);
+ LOG.debug("NAT Service : getFixedIpsForPort method is called for interface {}",interfname);
try {
Future<RpcResult<GetFixedIPsForNeutronPortOutput>> result =
neutronVpnService.getFixedIPsForNeutronPort(new GetFixedIPsForNeutronPortInputBuilder()