import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.config.rev151102.vtep.config.schemas.VtepConfigSchema;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.vtep.config.schemas.VtepConfigSchema;
-//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.op.rev150701.TunnelsState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList ;
public interface IITMProvider {
// APIs used by i
public DataBroker getDataBroker();
public void showTeps();
+ public void showState(TunnelList tunnels);
public void deleteVtep(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask,
String gatewayIp, String transportZone);
//Tunnel Monitoring
public static final boolean DEFAULT_MONITOR_ENABLED = true;
public static final int DEFAULT_MONITOR_INTERVAL = 10;
+ public static final int BFD_DEFAULT_MONITOR_INTERVAL = 100;
public static final String DUMMY_IP_ADDRESS = "0.0.0.0";
public static final String TUNNEL_TYPE_VXLAN = "VXLAN";
public static final String TUNNEL_TYPE_GRE = "GRE";
+ public static final String TUNNEL_TYPE_MPLS_OVER_GRE = "MPLS_OVER_GRE";
+ public static final String TUNNEL_TYPE_INVALID = "Invalid";
}
leaf destination-dpid {
type uint64;
}
+ leaf tunnel-type {
+ type identityref {
+ base odlif:tunnel-type-base;
+ }
+ }
}
output {
leaf interface-name {
leaf destination-ip {
type inet:ip-address;
}
+ leaf tunnel-type {
+ type identityref {
+ base odlif:tunnel-type-base;
+ }
+ }
}
output {
leaf interface-name {
leaf destination-node {
type string;
}
+ leaf tunnel-type {
+ type identityref {
+ base odlif:tunnel-type-base;
+ }
+ }
}
output {
leaf interface-name {
}
}
+ rpc add-l2-gw-mlag-device {
+ description "used for building tunnels between teps on all Dpns and hwVtep";
+ input {
+ leaf topology-id {
+ type string;
+ }
+ leaf-list node-id {
+ type string;
+ }
+ leaf ip-address {
+ type inet:ip-address;
+ }
+ }
+ }
rpc delete-l2-gw-device {
description "used for deleting tunnels between teps on all Dpns and hwVtep";
input {
}
}
+ rpc delete-l2-gw-mlag-device {
+ description "used for deleting tunnels between teps on all Dpns and hwVtep";
+ input {
+ leaf topology-id {
+ type string;
+ }
+ leaf-list node-id {
+ type string;
+ }
+ leaf ip-address {
+ type inet:ip-address;
+ }
+ }
+ }
}
\ No newline at end of file
/* Operational state */
+ identity tep-type-base {
+ description "Base TEP device type";
+ }
+ identity tep-type-internal {
+ base tep-type-base;
+ description "TEP type internal e.g. Compute OVS";
+ }
+ identity tep-type-external {
+ base tep-type-base;
+ description "TEP type external e.g. DC Gateway";
+ }
+ identity tep-type-hwvtep {
+ base tep-type-base;
+ description "TEP type Hwvtep e.g. TOR devices";
+ }
+ typedef tep-type {
+ type identityref {
+ base tep-type-base;
+ }
+ description "This type is used to refer to an TEP Device Type.";
+ }
container dpn-endpoints {
list DPN-TEPs-info {
/* Minimum 1 port. We may for now support only two ports */
list tunnel-end-points {
-
- key "portname VLAN-ID ip-address"; /* Multiple tunnels on the same physical port but on different VLAN can be supported */
+ ordered-by user;
+ key "portname VLAN-ID ip-address tunnel-type"; /* Multiple tunnels on the same physical port but on different VLAN can be supported */
leaf portname {
type string;
container tunnel-list {
list internal-tunnel {
- key "source-DPN destination-DPN";
+ key "source-DPN destination-DPN transport-type";
leaf source-DPN {
type uint64;
leaf destination-DPN {
type uint64;
}
+ leaf transport-type {
+ type identityref {
+ base odlif:tunnel-type-base;
+ }
+ }
/* logical-group interface id */
container external-tunnel-list {
list external-tunnel {
- key "source-device destination-device";
+ key "source-device destination-device transport-type";
leaf source-device {
type string; //dpnid or node-id
type string; //dpn-id or node-id or ip
}
+ leaf transport-type {
+ type identityref {
+ base odlif:tunnel-type-base;
+ }
+ }
/* logical-group interface id */
leaf tunnel-interface-name {
}
}
-
+ grouping tep-info-attributes {
+ leaf tep-device-type {
+ type identityref {
+ base tep-type-base;
+ }
+ }
+ leaf tep-device-id {
+ type string; //dpnid or node-id
+ }
+ leaf tep-ip {
+ type inet:ip-address; //dpnid or node-id
+ }
+ }
+
+ container tunnels_state {
+ list state-tunnel-list {
+ key "tunnel-interface-name";
+ leaf tunnel-interface-name {
+ type string;
+ }
+ leaf tunnel-state {
+ type boolean;
+ config false;
+ }
+ container src-info {
+ uses tep-info-attributes;
+ }
+ container dst-info {
+ uses tep-info-attributes;
+ }
+ leaf transport-type {
+ type identityref {
+ base odlif:tunnel-type-base;
+ }
+ }
+ }
+ }
notification itm-tunnel-build-complete{
}
container transport-zones {
list transport-zone {
+ ordered-by user;
key zone-name;
leaf zone-name {
type string;
import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
//import org.opendaylight.vpnservice.interfacemgr.util.OperationalIfmUtil;
import org.opendaylight.vpnservice.itm.globals.ITMConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan;
import org.opendaylight.vpnservice.itm.impl.ItmUtils;
import org.opendaylight.vpnservice.mdsalutil.MDSALDataStoreUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorEnabled;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorEnabledBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorInterval;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorIntervalBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList ;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeGre;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeVxlan;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.TransportZones;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.TransportZonesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.subnets.Vteps;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.subnets.VtepsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.subnets.VtepsKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
result.add(String.format("Tunnel Monitoring (for VXLAN tunnels): %s", (monitorEnabled ? "On" : "Off")));
result.add(String.format("Tunnel Monitoring Interval (for VXLAN tunnels): %d", monitorInterval));
result.add(System.lineSeparator());
- result.add(String.format("%-16s %-16s %-16s %-12s %-12s %-12s %-12s %-12s", "TransportZone", "TunnelType", "SubnetMask",
+ result.add(String.format("%-16s %-16s %-16s %-12s %-12s %-12s %-16s %-12s", "TransportZone", "TunnelType", "SubnetMask",
"GatewayIP", "VlanID", "DpnID", "IPAddress", "PortName"));
- result.add("--------------------------------------------------------------------------------------------------------------");
+ result.add("------------------------------------------------------------------------------------------------------------------------------");
for (TransportZone tZ : tZones.getTransportZone()) {
if (tZ.getSubnets() == null || tZ.getSubnets().isEmpty()) {
LOG.error("Transport Zone " + tZ.getZoneName() + "has no subnets");
strTunnelType = ITMConstants.TUNNEL_TYPE_GRE ;
else
strTunnelType = ITMConstants.TUNNEL_TYPE_VXLAN ;
- result.add(String.format("%-16s %-16s %-16s %-12s %-12s %-12s %-12s %-12s", tZ.getZoneName(), strTunnelType, sub
+ result.add(String.format("%-16s %-16s %-16s %-12s %-12s %-12s %-16s %-12s", tZ.getZoneName(), strTunnelType, sub
.getPrefix().getIpv4Prefix().getValue(), sub.getGatewayIp().getIpv4Address()
.getValue(), sub.getVlanId().toString(), vtep.getDpnId().toString(), vtep
.getIpAddress().getIpv4Address().getValue(), vtep.getPortname().toString()));
e.printStackTrace();
}
}
-/*
- public void showState(TunnelsState tunnelsState, boolean tunnelMonitorEnabled) {
- List<StateTunnelList> tunnelLists = tunnelsState.getStateTunnelList();
+
+ public void showState(TunnelList tunnels, boolean tunnelMonitorEnabled) {
+ IfTunnel tunnelInterface = null;
+ IfL2vlan l2Vlan = null;
+ List<InternalTunnel> tunnelLists = tunnels.getInternalTunnel();
if (tunnelLists == null || tunnelLists.isEmpty()) {
- System.out.println("No Logical Tunnels Exist");
+ System.out.println("No Internal Tunnels Exist");
return;
}
if (!tunnelMonitorEnabled) {
System.out.println("Tunnel Monitoring is Off");
}
- System.out.println(String.format("%-16s %-16s %-16s %-10s %-16s %-8s %-10s %-10s", "Source-DPN",
- "Destination-DPN", "SourcePortName", "Source-IP", "Destination-IP", "VLan-ID", "Trunk-State",
- "Logical-Tunnel-State"));
- System.out.println("----------------------------------------------------------------------------------------------------------------------");
-
- for (StateTunnelList tunnel : tunnelLists) {
- String logicaltunnelState = (tunnel.isLogicalTunnelState()) ? "UP" : "DOWN";
- try {
- List<String> trunks =
- interfaceManager.getTunnelInterfacesOfLogicalGroup(tunnel.getLogicalTunnelGroupName());
- if (trunks != null && !trunks.isEmpty()) {
- for (String trunk : trunks) {
- List<String> params = Arrays.asList(trunk.split(":"));
- LOG.trace("trunk {} for LogicalIf {} ", trunk, tunnel.getLogicalTunnelGroupName());
- String trunkState = (OperationalIfmUtil.isInterfaceUp(dataBroker, trunk)) ? "UP" : "DOWN";
- System.out.println(String.format("%-16s %-16s %-16s %-10s %-16s %-8s %-10s %-10s", tunnel
- .getSourceDPN().toString(), tunnel.getDestinationDPN().toString(), params
- .get(1), params.get(3), params.get(4), params.get(2), trunkState,
- logicaltunnelState));
- }
- } else {
- LOG.error("No trunks for " + tunnel.getLogicalTunnelGroupName());
+ String displayFormat = "%-16s %-16s %-16s %-16s %-16s %-8s %-10s %-10s";
+ System.out.println(String.format(displayFormat, "Tunnel Name", "Source-DPN",
+ "Destination-DPN", "Source-IP", "Destination-IP", "Vlan Id", "Trunk-State", "Transport Type"));
+ System.out.println("-------------------------------------------------------------------------------------------------------------------------------------");
+
+ for (InternalTunnel tunnel : tunnelLists) {
+ String tunnelInterfaceName = tunnel.getTunnelInterfaceName();
+ LOG.trace("tunnelInterfaceName::: {}", tunnelInterfaceName);
+
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
+ ItmUtils.buildStateInterfaceId(tunnelInterfaceName);
+ Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateOptional =
+ ItmUtils.read(LogicalDatastoreType.OPERATIONAL, ifStateId, dataBroker);
+ String tunnelState = "DOWN" ;
+ if (ifStateOptional.isPresent()) {
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface iface = ifStateOptional.get() ;
+ if(iface.getAdminStatus() == AdminStatus.Up && iface.getOperStatus() == OperStatus.Up)
+ tunnelState = "UP" ;
+ }
+ InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(tunnelInterfaceName);
+ Optional<Interface> ifaceObj = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, dataBroker) ;
+ if (ifaceObj.isPresent()) {
+ l2Vlan = (IfL2vlan) ifaceObj.get().getAugmentation(IfL2vlan.class);
+ tunnelInterface = (IfTunnel) ifaceObj.get().getAugmentation(IfTunnel.class);
}
- } catch (InterfaceNotFoundException e) {
- LOG.error("if not found " + tunnel.getLogicalTunnelGroupName());
- }
- }
+ Class<? extends TunnelTypeBase> tunType = tunnelInterface.getTunnelInterfaceType();
+ String tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
+ if( tunType.equals(TunnelTypeVxlan.class))
+ tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN ;
+ else if( tunType.equals(TunnelTypeGre.class) )
+ tunnelType = ITMConstants.TUNNEL_TYPE_GRE ;
+ int vlanId = 0;
+ if( l2Vlan != null ) {
+ vlanId = l2Vlan.getVlanId().getValue() ;
+ }
+ System.out.println(String.format(displayFormat, tunnel.getTunnelInterfaceName(), tunnel
+ .getSourceDPN().toString(), tunnel.getDestinationDPN().toString(), tunnelInterface.getTunnelSource().getIpv4Address().getValue(), tunnelInterface.getTunnelDestination().getIpv4Address().getValue(),vlanId, tunnelState ,
+ tunnelType));
+ }
}
-*/
+
// deletes from ADD-cache if it exists.
public boolean isInCache(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask,
String gatewayIp, String transportZone) {
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.vpnservice.itm.api.IITMProvider;
import org.opendaylight.vpnservice.itm.impl.ItmUtils;
-//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.op.rev150701.TunnelsState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList ;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import java.util.ArrayList;
@Override
protected Object doExecute() throws Exception {
- /*
+
DataBroker broker = itmProvider.getDataBroker();
List<String> result = new ArrayList<String>();
- InstanceIdentifier<TunnelsState> path = InstanceIdentifier.builder(TunnelsState.class).build();
- Optional<TunnelsState> tunnels = ItmUtils.read(LogicalDatastoreType.OPERATIONAL, path, broker);
+ InstanceIdentifier<TunnelList> path = InstanceIdentifier.builder(TunnelList.class).build();
+ Optional<TunnelList> tunnels = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, broker);
if (tunnels.isPresent()) {
itmProvider.showState(tunnels.get());
}
else
- System.out.println("No Logical Tunnels Exist");
- */
- System.out.println( "Logical Tunnels state is not currently supported");
+ System.out.println("No Internal Tunnels Exist");
return null;
}
}
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.vpnservice.itm.globals.ITMConstants;
import org.opendaylight.vpnservice.itm.impl.ItmUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
// CHECK -- Assumption -- Only one End Point / Dpn for GRE/Vxlan Tunnels
TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0);
String interfaceName = firstEndPt.getInterfaceName();
- String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName, firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue());
+ String tunTypeStr = tunType.getName();
+ String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName, firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue(), tunTypeStr);
char[] subnetMaskArray = firstEndPt.getSubnetMask().getValue();
String subnetMaskStr = String.valueOf(subnetMaskArray);
SubnetUtils utils = new SubnetUtils(subnetMaskStr);
String dcGwyIpStr = String.valueOf(extIp.getValue());
- IpAddress gwyIpAddress = (utils.getInfo().isInRange(dcGwyIpStr)) ? null : firstEndPt.getGwIpAddress();
- String ifDescription = tunType.getName();
+ IpAddress gatewayIpObj = new IpAddress("0.0.0.0".toCharArray());
+ IpAddress gwyIpAddress = (utils.getInfo().isInRange(dcGwyIpStr)) ? gatewayIpObj : firstEndPt.getGwIpAddress();
logger.debug(" Creating Trunk Interface with parameters trunk I/f Name - {}, parent I/f name - {}, source IP - {}, DC Gateway IP - {} gateway IP - {}", trunkInterfaceName, interfaceName, firstEndPt.getIpAddress(), extIp, gwyIpAddress);
- Interface iface = ItmUtils.buildTunnelInterface(teps.getDPNID(), trunkInterfaceName, String.format("%s %s", ifDescription, "Trunk Interface"), true, tunType, firstEndPt.getIpAddress(), extIp, gwyIpAddress, firstEndPt.getVLANID(), false,false,null);
+ Interface iface = ItmUtils.buildTunnelInterface(teps.getDPNID(), trunkInterfaceName, String.format("%s %s", ItmUtils.convertTunnelTypetoString(tunType), "Trunk Interface"), true, tunType, firstEndPt.getIpAddress(), extIp, gwyIpAddress, firstEndPt.getVLANID(), false,false,null);
logger.debug(" Trunk Interface builder - {} ", iface);
InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
logger.debug(" Trunk Interface Identifier - {} ", trunkIdentifier);
// update external_tunnel_list ds
InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
ExternalTunnelList.class)
- .child(ExternalTunnel.class, new ExternalTunnelKey(extIp.toString(), teps.getDPNID().toString()));
- ExternalTunnel tnl = ItmUtils.buildExternalTunnel(teps.getDPNID().toString(), extIp.toString(), trunkInterfaceName);
+ .child(ExternalTunnel.class, new ExternalTunnelKey(extIp.toString(), teps.getDPNID().toString(), tunType));
+ ExternalTunnel tnl = ItmUtils.buildExternalTunnel( teps.getDPNID().toString(), extIp.toString(),
+ tunType, trunkInterfaceName);
t.merge(LogicalDatastoreType.CONFIGURATION, path, tnl, true);
}
futures.add(t.submit());
String cssID = dpn.getDPNID().toString();
String nodeId = hwVtepDS.getNodeId();
//CSS-TOR
+ Boolean monitorEnabled = ItmUtils.readMonitoringStateFromDS(dataBroker);
+ Integer monitorInterval = ItmUtils.readMonitorIntervalfromDS(dataBroker);
logger.trace("wire up {} and {}",tep, hwVtepDS);
if (!wireUp(dpn.getDPNID(), tep.getPortname(), sub.getVlanId(), tep.getIpAddress(), nodeId, hwVtepDS.getIpAddress(), tep.getSubnetMask(),
- sub.getGatewayIp(), sub.getPrefix(), tZone.getTunnelType(), idManagerService, dataBroker, futures, t))
+ sub.getGatewayIp(), sub.getPrefix(), tZone.getTunnelType(),monitorEnabled,ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, idManagerService, dataBroker, futures, t))
logger.error("Unable to build tunnel {} -- {}", tep.getIpAddress(), hwVtepDS.getIpAddress());
//TOR-CSS
logger.trace("wire up {} and {}", hwVtepDS,tep);
if (!wireUp(hwVtepDS.getTopologyId(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(), cssID, tep.getIpAddress(), sub.getPrefix(),
- sub.getGatewayIp(), tep.getSubnetMask(), tZone.getTunnelType(), idManagerService, dataBroker, futures, t))
+ sub.getGatewayIp(), tep.getSubnetMask(), tZone.getTunnelType(), monitorEnabled,ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, idManagerService, dataBroker, futures, t))
logger.error("Unable to build tunnel {} -- {}", hwVtepDS.getIpAddress(), tep.getIpAddress());
}
for (HwVtep hwTep : cfgdHwVteps) {
InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey((hwTep.getTransportZone()))).build();
Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker);
+ Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
if (tZoneOptional.isPresent()) {
TransportZone tZone = tZoneOptional.get();
//do we need to check tunnel type?
if (hwVtepDS.getIpAddress().equals(hwTep.getHwIp()))
continue;//dont mesh with self
//TOR1-TOR2
+ Boolean monitorEnabled = ItmUtils.readMonitoringStateFromDS(dataBroker);
+ Integer monitorInterval = ItmUtils.readMonitorIntervalfromDS(dataBroker);
logger.trace("wire up {} and {}",hwTep, hwVtepDS);
if (!wireUp(hwTep.getTopo_id(), hwTep.getNode_id(), hwTep.getHwIp(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(),
- hwTep.getIpPrefix(), hwTep.getGatewayIP(), sub.getPrefix(), tZone.getTunnelType(), idManagerService, dataBroker, futures, t))
+ hwTep.getIpPrefix(), hwTep.getGatewayIP(), sub.getPrefix(), tunType,monitorEnabled,
+ ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, idManagerService, dataBroker, futures, t))
logger.error("Unable to build tunnel {} -- {}", hwTep.getHwIp(), hwVtepDS.getIpAddress());
//TOR2-TOR1
logger.trace("wire up {} and {}", hwVtepDS,hwTep);
if (!wireUp(hwTep.getTopo_id(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(), hwTep.getNode_id(), hwTep.getHwIp(),
- sub.getPrefix(), sub.getGatewayIp(), hwTep.getIpPrefix(), tZone.getTunnelType(), idManagerService, dataBroker, futures, t))
+ sub.getPrefix(), sub.getGatewayIp(), hwTep.getIpPrefix(), tunType, monitorEnabled,ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, idManagerService, dataBroker, futures, t))
logger.error("Unable to build tunnel {} -- {}", hwVtepDS.getIpAddress(), hwTep.getHwIp());
}
}
for (Vteps vtep : sub.getVteps()) {
//TOR-CSS
String cssID = vtep.getDpnId().toString();
+ Boolean monitorEnabled = ItmUtils.readMonitoringStateFromDS(dataBroker);
+ Integer monitorInterval = ItmUtils.readMonitorIntervalfromDS(dataBroker);
logger.trace("wire up {} and {}",hwTep, vtep);
if(!wireUp(hwTep.getTopo_id(), hwTep.getNode_id(), hwTep.getHwIp(), cssID, vtep.getIpAddress(), hwTep.getIpPrefix(),
- hwTep.getGatewayIP(), sub.getPrefix(), tZone.getTunnelType(),idManagerService, dataBroker, futures, t ))
+ hwTep.getGatewayIP(), sub.getPrefix(), tunType,monitorEnabled, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, idManagerService, dataBroker, futures, t ))
logger.error("Unable to build tunnel {} -- {}", hwTep.getHwIp(), vtep.getIpAddress());
//CSS-TOR
logger.trace("wire up {} and {}", vtep,hwTep);
if(!wireUp(vtep.getDpnId(), vtep.getPortname(), sub.getVlanId(), vtep.getIpAddress(),
- hwTep.getNode_id(),hwTep.getHwIp(),sub.getPrefix(), sub.getGatewayIp(),hwTep.getIpPrefix(),tZone.getTunnelType(),idManagerService, dataBroker, futures, t ));
+ hwTep.getNode_id(),hwTep.getHwIp(),sub.getPrefix(), sub.getGatewayIp(),hwTep.getIpPrefix(),
+ tunType,monitorEnabled,ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL,idManagerService, dataBroker, futures, t ));
}
//for tunnels from TOR device
private static boolean wireUp(String topo_id, String srcNodeid, IpAddress srcIp, String dstNodeId, IpAddress dstIp, IpPrefix srcSubnet,
- IpAddress gWIp, IpPrefix dstSubnet, Class<? extends TunnelTypeBase> tunType, IdManagerService idManagerService, DataBroker dataBroker, List<ListenableFuture<Void>> futures, WriteTransaction t) {
- IpAddress gwyIpAddress = (srcSubnet.equals(dstSubnet)) ? null : gWIp;
+ IpAddress gWIp, IpPrefix dstSubnet, Class<? extends TunnelTypeBase> tunType,Boolean monitorEnabled,
+ Integer monitorInterval,IdManagerService idManagerService, DataBroker dataBroker, List<ListenableFuture<Void>> futures, WriteTransaction t) {
+ IpAddress gatewayIpObj = new IpAddress("0.0.0.0".toCharArray());
+ IpAddress gwyIpAddress = (srcSubnet.equals(dstSubnet)) ? gatewayIpObj : gWIp;
String parentIf = ItmUtils.getHwParentIf(topo_id, srcNodeid);
- String tunnelIfName = ItmUtils.getTrunkInterfaceName(idManagerService, parentIf, srcIp.getIpv4Address().getValue(), dstIp.getIpv4Address().getValue());
+ String tunTypeStr = tunType.getName();
+ String tunnelIfName = ItmUtils.getTrunkInterfaceName(idManagerService, parentIf,
+ srcIp.getIpv4Address().getValue(), dstIp.getIpv4Address().getValue(), tunTypeStr);
logger.debug(" Creating ExternalTrunk Interface with parameters Name - {}, parent I/f name - {}, source IP - {}, destination IP - {} gateway IP - {}", tunnelIfName, parentIf, srcIp, dstIp, gwyIpAddress);
Interface hwTunnelIf = ItmUtils.buildHwTunnelInterface(tunnelIfName, String.format("%s %s", tunType.getName(), "Trunk Interface"),
- true, topo_id, srcNodeid, tunType, srcIp, dstIp, gwyIpAddress, true);
+ true, topo_id, srcNodeid, tunType, srcIp, dstIp, gwyIpAddress, monitorEnabled, monitorInterval);
InstanceIdentifier<Interface> ifIID = InstanceIdentifier.builder(Interfaces.class).child(Interface.class, new InterfaceKey(tunnelIfName)).build();
logger.trace(" Writing Trunk Interface to Config DS {}, {} ", ifIID, hwTunnelIf);
+ ItmUtils.itmCache.addInterface(hwTunnelIf);
t.merge(LogicalDatastoreType.CONFIGURATION, ifIID, hwTunnelIf, true);
// also update itm-state ds?
InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
ExternalTunnelList.class)
- .child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey(dstNodeId), getExternalTunnelKey(srcNodeid)));
- ExternalTunnel tnl = ItmUtils.buildExternalTunnel(getExternalTunnelKey(srcNodeid), getExternalTunnelKey(dstNodeId), tunnelIfName);
+ .child(ExternalTunnel.class, new ExternalTunnelKey( getExternalTunnelKey(dstNodeId), getExternalTunnelKey(srcNodeid), tunType));
+ ExternalTunnel tnl = ItmUtils.buildExternalTunnel( getExternalTunnelKey(srcNodeid),
+ getExternalTunnelKey(dstNodeId),
+ tunType, tunnelIfName);
t.merge(LogicalDatastoreType.CONFIGURATION, path, tnl, true);
+ ItmUtils.itmCache.addExternalTunnel(tnl);
return true;
}
//for tunnels from CSS
private static boolean wireUp(BigInteger dpnId,String portname, Integer vlanId, IpAddress srcIp, String dstNodeId, IpAddress dstIp, IpPrefix srcSubnet,
- IpAddress gWIp, IpPrefix dstSubnet, Class<? extends TunnelTypeBase> tunType, IdManagerService idManagerService, DataBroker dataBroker, List<ListenableFuture<Void>> futures, WriteTransaction t) {
- IpAddress gwyIpAddress = (srcSubnet.equals(dstSubnet)) ? null : gWIp;
+ IpAddress gWIp, IpPrefix dstSubnet, Class<? extends TunnelTypeBase> tunType,Boolean monitorEnabled, Integer monitorInterval,
+ IdManagerService idManagerService, DataBroker dataBroker, List<ListenableFuture<Void>> futures, WriteTransaction t) {
+ IpAddress gatewayIpObj = new IpAddress("0.0.0.0".toCharArray());
+ IpAddress gwyIpAddress = (srcSubnet.equals(dstSubnet)) ? gatewayIpObj : gWIp;
String parentIf = ItmUtils.getInterfaceName(dpnId, portname, vlanId);
- String tunnelIfName = ItmUtils.getTrunkInterfaceName(idManagerService, parentIf, srcIp.getIpv4Address().getValue(), dstIp.getIpv4Address().getValue());
+ String tunTypeStr = tunType.getName();
+ String tunnelIfName = ItmUtils.getTrunkInterfaceName(idManagerService, parentIf,
+ srcIp.getIpv4Address().getValue(), dstIp.getIpv4Address().getValue(), tunTypeStr);
logger.debug(" Creating ExternalTrunk Interface with parameters Name - {}, parent I/f name - {}, source IP - {}, destination IP - {} gateway IP - {}", tunnelIfName, parentIf, srcIp, dstIp, gwyIpAddress);
- Interface extTunnelIf = ItmUtils.buildTunnelInterface(dpnId, tunnelIfName, String.format("%s %s", tunType.getName(), "Trunk Interface"), true, tunType, srcIp, dstIp, gwyIpAddress, vlanId, false, true, 5L);
+ Interface extTunnelIf = ItmUtils.buildTunnelInterface(dpnId, tunnelIfName, String.format("%s %s", tunType.getName(), "Trunk Interface"), true, tunType, srcIp, dstIp, gwyIpAddress, vlanId, false,monitorEnabled, monitorInterval);
InstanceIdentifier<Interface> ifIID = InstanceIdentifier.builder(Interfaces.class).child(Interface.class, new InterfaceKey(tunnelIfName)).build();
logger.trace(" Writing Trunk Interface to Config DS {}, {} ", ifIID, extTunnelIf);
t.merge(LogicalDatastoreType.CONFIGURATION, ifIID, extTunnelIf, true);
+ ItmUtils.itmCache.addInterface(extTunnelIf);
InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
ExternalTunnelList.class)
- .child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey(dstNodeId), dpnId.toString()));
- ExternalTunnel tnl = ItmUtils.buildExternalTunnel(dpnId.toString(), getExternalTunnelKey(dstNodeId), tunnelIfName);
+ .child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey(dstNodeId), dpnId.toString(), tunType));
+ ExternalTunnel tnl = ItmUtils.buildExternalTunnel( dpnId.toString(),
+ getExternalTunnelKey(dstNodeId),
+ tunType, tunnelIfName);
t.merge(LogicalDatastoreType.CONFIGURATION, path, tnl, true);
+ ItmUtils.itmCache.addExternalTunnel(tnl);
return true;
}
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.vpnservice.itm.globals.ITMConstants;
import org.opendaylight.vpnservice.itm.impl.ItmUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeGre;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeVxlan;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
}
for( DPNTEPsInfo teps : dpnTepsList) {
TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0) ;
- if( firstEndPt.getTunnelType().equals(tunType)) {
String interfaceName = firstEndPt.getInterfaceName() ;
- String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName,firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue()) ;
+ String trunkInterfaceName = ItmUtils.getTrunkInterfaceName( idManagerService, interfaceName,
+ firstEndPt.getIpAddress().getIpv4Address().getValue(),
+ extIp.getIpv4Address().getValue(),
+ tunType.getName());
InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+ ItmUtils.itmCache.removeInterface(trunkInterfaceName);
InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
ExternalTunnelList.class)
- .child(ExternalTunnel.class, getExternalTunnelKey(extIp.toString(), teps.getDPNID().toString()));
+ .child(ExternalTunnel.class, ItmUtils.getExternalTunnelKey(extIp.toString(),
+ teps.getDPNID().toString(),
+ tunType));
t.delete(LogicalDatastoreType.CONFIGURATION, path);
+ logger.debug( "Deleting tunnel towards DC gateway, Tunnel interface name {} ",trunkInterfaceName );
+ ItmUtils.itmCache.removeExternalTunnel(trunkInterfaceName);
// Release the Ids for the trunk interface Name
- ItmUtils.releaseIdForTrunkInterfaceName(idManagerService,interfaceName,firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue() );
+ ItmUtils.releaseIdForTrunkInterfaceName(idManagerService,interfaceName,firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue(),tunType.getName());
}
- }
futures.add(t.submit()) ;
return futures ;
}
public static List<ListenableFuture<Void>> deleteHwVtepsTunnels(DataBroker dataBroker, IdManagerService idManagerService, List<DPNTEPsInfo> delDpnList ,List<HwVtep> cfgdHwVteps) {
List<ListenableFuture<Void>> futures = new ArrayList<>();
WriteTransaction t = dataBroker.newWriteOnlyTransaction();
- if (null != delDpnList) {
- tunnelsFromCSS(delDpnList, idManagerService , futures, t , dataBroker);
- }
- if (null != cfgdHwVteps) {
- tunnelsFromhWVtep(cfgdHwVteps, idManagerService, futures, t, dataBroker);
- }
if (delDpnList != null || cfgdHwVteps != null)
+ tunnelsDeletion(delDpnList, cfgdHwVteps, idManagerService, futures, t, dataBroker);
futures.add(t.submit());
return futures;
}
- private static void tunnelsFromCSS(List<DPNTEPsInfo> cfgdDpnList, IdManagerService idManagerService, List<ListenableFuture<Void>> futures, WriteTransaction t, DataBroker dataBroker) {
+ private static void tunnelsDeletion(List<DPNTEPsInfo> cfgdDpnList, List<HwVtep> cfgdhwVteps, IdManagerService idManagerService, List<ListenableFuture<Void>> futures, WriteTransaction t, DataBroker dataBroker) {
+ if (cfgdDpnList != null && !cfgdDpnList.isEmpty()) {
for (DPNTEPsInfo dpn : cfgdDpnList) {
if (dpn.getTunnelEndPoints() != null && !dpn.getTunnelEndPoints().isEmpty())
for (TunnelEndPoints srcTep : dpn.getTunnelEndPoints()) {
- InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey((srcTep.getTransportZone()))).build();
+ InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class)
+ .child(TransportZone.class, new TransportZoneKey((srcTep.getTransportZone())))
+ .build();
Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker);
if (tZoneOptional.isPresent()) {
TransportZone tZone = tZoneOptional.get();
for (DeviceVteps hwVtepDS : sub.getDeviceVteps()) {
String cssID = dpn.getDPNID().toString();
//CSS-TOR-CSS
- deleteTrunksCSSTOR(dataBroker, idManagerService, dpn.getDPNID(),
- srcTep.getInterfaceName(), srcTep.getIpAddress(),
- hwVtepDS.getTopologyId(), hwVtepDS.getNodeId(),
- hwVtepDS.getIpAddress(), t, futures);
+ deleteTrunksCSSTOR(dataBroker, idManagerService, dpn.getDPNID(), srcTep.getInterfaceName(), srcTep.getIpAddress(),
+ hwVtepDS.getTopologyId(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(), tZone.getTunnelType(),
+ t, futures);
+ }
+ }
+ }
+ }
+ if (cfgdhwVteps != null && !cfgdhwVteps.isEmpty()) {
+ for (HwVtep hwVtep : cfgdhwVteps) {
+ deleteTrunksCSSTOR(dataBroker, idManagerService, dpn.getDPNID(), srcTep.getInterfaceName(), srcTep.getIpAddress(),
+ hwVtep.getTopo_id(), hwVtep.getNode_id(), hwVtep.getHwIp(),
+ TunnelTypeVxlan.class, t, futures);
+ }
+ }
+ }
+ }
+ }
+ }
+ if (cfgdhwVteps != null && !cfgdhwVteps.isEmpty()) {
+ for (HwVtep hwTep : cfgdhwVteps) {
+ logger.trace("processing hwTep from list {}", hwTep);
+ for (HwVtep hwTepRemote : cfgdhwVteps) {
+ if (!hwTep.getHwIp().equals(hwTepRemote.getHwIp())) {
+ deleteTrunksTORTOR(dataBroker, idManagerService, hwTep.getTopo_id(), hwTep.getNode_id(),
+ hwTep.getHwIp(), hwTepRemote.getTopo_id(), hwTepRemote.getNode_id(),
+ hwTepRemote.getHwIp(), TunnelTypeVxlan.class, t, futures);
+ }
+ }
+ InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class)
+ .child(TransportZone.class, new TransportZoneKey((hwTep.getTransportZone()))).build();
+ Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker);
+ if (tZoneOptional.isPresent()) {
+ TransportZone tZone = tZoneOptional.get();
+ logger.trace("subnets under tz {} are {}", tZone.getZoneName(), tZone.getSubnets());
+ if (tZone.getSubnets() != null && !tZone.getSubnets().isEmpty()) {
+ for (Subnets sub : tZone.getSubnets()) {
+ if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
+ for (DeviceVteps hwVtepDS : sub.getDeviceVteps()) {
+ logger.trace("hwtepDS exists {}", hwVtepDS);
+ if (hwVtepDS.getIpAddress().equals(hwTep.getHwIp()))
+ continue;//dont delete tunnels with self
+ logger.trace("deleting tor-tor {} and {}", hwTep, hwVtepDS);
+ deleteTrunksTORTOR(dataBroker, idManagerService, hwTep.getTopo_id(), hwTep.getNode_id(),
+ hwTep.getHwIp(), hwVtepDS.getTopologyId(), hwVtepDS.getNodeId(),
+ hwVtepDS.getIpAddress(), tZone.getTunnelType(),
+ t, futures);
}
}
+ if (sub.getVteps() != null && !sub.getVteps().isEmpty()) {
+ for (Vteps vtep : sub.getVteps()) {
+ logger.trace("deleting tor-css-tor {} and {}", hwTep, vtep);
+ String parentIf = ItmUtils.getInterfaceName(vtep.getDpnId(), vtep.getPortname(), sub.getVlanId());
+ deleteTrunksCSSTOR(dataBroker, idManagerService, vtep.getDpnId(), parentIf, vtep.getIpAddress(),
+ hwTep.getTopo_id(), hwTep.getNode_id(), hwTep.getHwIp(),
+ tZone.getTunnelType(), t, futures);
+ }
+ }
}
}
}
- private static void tunnelsFromhWVtep(List<HwVtep> cfgdHwVteps, IdManagerService idManagerService, List<ListenableFuture<Void>> futures, WriteTransaction t, DataBroker dataBroker) {
- for (HwVtep hwTep : cfgdHwVteps) {
- logger.trace("processing hwTep from list {}",hwTep);
- InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey((hwTep.getTransportZone()))).build();
- Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker);
- if (tZoneOptional.isPresent()) {
- TransportZone tZone = tZoneOptional.get();
//do we need to check tunnel type?
- logger.trace("subnets under tz {} are {}",tZone.getZoneName(),tZone.getSubnets());
- if (tZone.getSubnets() != null && !tZone.getSubnets().isEmpty()) {
- for (Subnets sub : tZone.getSubnets()) {
- if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
- for (DeviceVteps hwVtepDS : sub.getDeviceVteps()) {
- logger.trace("hwtepDS exists {}",hwVtepDS);
//do i need to check node-id?
//for mlag case and non-m-lag case, isnt it enough to just check ipaddress?
- if (hwVtepDS.getIpAddress().equals(hwTep.getHwIp()))
- continue;//dont delete tunnels with self
//TOR-TOR
- logger.trace("deleting tor-tor {} and {}",hwTep,hwVtepDS);
- deleteTrunksTORTOR(dataBroker, idManagerService, hwTep.getTopo_id(), hwTep.getNode_id(),
- hwTep.getHwIp(), hwVtepDS.getTopologyId(), hwVtepDS.getNodeId(),
- hwVtepDS.getIpAddress(), t, futures);
- }
- }
- if (sub.getVteps() != null && !sub.getVteps().isEmpty()) {
- for (Vteps vtep : sub.getVteps()) {
//TOR-CSS
- logger.trace("deleting tor-css-tor {} and {}",hwTep,vtep);
- String parentIf = ItmUtils.getInterfaceName(vtep.getDpnId(),vtep.getPortname(),sub.getVlanId());
- deleteTrunksCSSTOR(dataBroker,idManagerService,vtep.getDpnId(),parentIf,vtep.getIpAddress(),
- hwTep.getTopo_id(),hwTep.getNode_id(),hwTep.getHwIp(),t,futures );
- }
- }
- }
- }
- }
- }
- }
private static void deleteTrunksCSSTOR(DataBroker dataBroker, IdManagerService idManagerService, BigInteger dpnid,
String interfaceName, IpAddress cssIpAddress, String topologyId, String nodeId, IpAddress hWIpAddress,
- WriteTransaction t, List<ListenableFuture<Void>> futures) {
+ Class<? extends TunnelTypeBase> tunType, WriteTransaction t,
+ List<ListenableFuture<Void>> futures) {
//CSS-TOR
- if (trunkExists(dpnid.toString(), nodeId,dataBroker)) {
+ if (trunkExists(dpnid.toString(), nodeId, tunType, dataBroker)) {
logger.trace("deleting tunnel from {} to {} ", dpnid.toString(), nodeId);
String parentIf = interfaceName;
String fwdTrunkIf = ItmUtils.getTrunkInterfaceName(idManagerService,parentIf,cssIpAddress.getIpv4Address().getValue(),
- hWIpAddress.getIpv4Address().getValue());
+ hWIpAddress.getIpv4Address().getValue(), tunType.getName());
InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(fwdTrunkIf);
t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
ExternalTunnelList.class)
- .child(ExternalTunnel.class, getExternalTunnelKey(nodeId, dpnid.toString()));
+ .child(ExternalTunnel.class, ItmUtils.getExternalTunnelKey(nodeId, dpnid.toString(), tunType));
t.delete(LogicalDatastoreType.CONFIGURATION, path);
}
else {
logger.trace(" trunk from {} to {} already deleted",dpnid.toString(), nodeId);
}
//TOR-CSS
- if (trunkExists( nodeId, dpnid.toString(),dataBroker)) {
+ if (trunkExists( nodeId, dpnid.toString(), tunType, dataBroker)) {
logger.trace("deleting tunnel from {} to {} ",nodeId, dpnid.toString());
String parentIf = ItmUtils.getHwParentIf(topologyId,nodeId);
String revTrunkIf = ItmUtils.getTrunkInterfaceName(idManagerService,parentIf, hWIpAddress.getIpv4Address().getValue(),
- cssIpAddress.getIpv4Address().getValue());
+ cssIpAddress.getIpv4Address().getValue(), tunType.getName());
InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(revTrunkIf);
t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
ExternalTunnelList.class)
- .child(ExternalTunnel.class, getExternalTunnelKey( dpnid.toString(),nodeId));
+ .child(ExternalTunnel.class, ItmUtils.getExternalTunnelKey(dpnid.toString(),nodeId, tunType));
t.delete(LogicalDatastoreType.CONFIGURATION, path);
}
else {
private static void deleteTrunksTORTOR(DataBroker dataBroker, IdManagerService idManagerService,
String topologyId1, String nodeId1, IpAddress hWIpAddress1, String topologyId2, String nodeId2, IpAddress hWIpAddress2,
- WriteTransaction t, List<ListenableFuture<Void>> futures) {
+ Class<? extends TunnelTypeBase> tunType, WriteTransaction t, List<ListenableFuture<Void>> futures) {
//TOR1-TOR2
- if (trunkExists(nodeId1, nodeId2,dataBroker)) {
+ if (trunkExists(nodeId1, nodeId2, tunType, dataBroker)) {
logger.trace("deleting tunnel from {} to {} ", nodeId1, nodeId2);
String parentIf = ItmUtils.getHwParentIf(topologyId1,nodeId1);
String fwdTrunkIf = ItmUtils.getTrunkInterfaceName(idManagerService, parentIf,
- hWIpAddress1.getIpv4Address().getValue(), hWIpAddress2.getIpv4Address().getValue());
+ hWIpAddress1.getIpv4Address().getValue(),
+ hWIpAddress2.getIpv4Address().getValue(),
+ tunType.getName());
InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(fwdTrunkIf);
t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
ExternalTunnelList.class)
- .child(ExternalTunnel.class, getExternalTunnelKey(nodeId2, nodeId1));
+ .child(ExternalTunnel.class, ItmUtils.getExternalTunnelKey(nodeId2, nodeId1, tunType));
t.delete(LogicalDatastoreType.CONFIGURATION, path);
}
else {
logger.trace(" trunk from {} to {} already deleted",nodeId1, nodeId2);
}
//TOR2-TOR1
- if (trunkExists( nodeId2, nodeId1,dataBroker)) {
+ if (trunkExists( nodeId2, nodeId1, tunType, dataBroker)) {
logger.trace("deleting tunnel from {} to {} ",nodeId2, nodeId1);
String parentIf = ItmUtils.getHwParentIf(topologyId2,nodeId2);
String revTrunkIf = ItmUtils.getTrunkInterfaceName(idManagerService,parentIf, hWIpAddress2.getIpv4Address().getValue(),
- hWIpAddress1.getIpv4Address().getValue());
+ hWIpAddress1.getIpv4Address().getValue(), tunType.getName());
InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(revTrunkIf);
t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
ExternalTunnelList.class)
- .child(ExternalTunnel.class, getExternalTunnelKey( nodeId1,nodeId2));
+ .child(ExternalTunnel.class, ItmUtils.getExternalTunnelKey(nodeId1,nodeId2, tunType));
t.delete(LogicalDatastoreType.CONFIGURATION, path);
}
else {
}
}
- private static boolean trunkExists( String srcDpnOrNode, String dstDpnOrNode, DataBroker dataBroker) {
+ private static boolean trunkExists( String srcDpnOrNode, String dstDpnOrNode,
+ Class<? extends TunnelTypeBase> tunType,DataBroker dataBroker) {
boolean existsFlag = false ;
InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
ExternalTunnelList.class)
- .child(ExternalTunnel.class, getExternalTunnelKey(dstDpnOrNode, srcDpnOrNode));
+ .child(ExternalTunnel.class, ItmUtils.getExternalTunnelKey(dstDpnOrNode, srcDpnOrNode, tunType));
Optional<ExternalTunnel> exTunnels = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,path, dataBroker) ;
- if( exTunnels.isPresent())
+ if( exTunnels.isPresent()) {
existsFlag = true ;
- return existsFlag ;
}
-
- static ExternalTunnelKey getExternalTunnelKey(String dst , String src) {
- if (src.indexOf("physicalswitch") > 0) {
- src = src.substring(0, src.indexOf("physicalswitch") - 1);
- }
- if (dst.indexOf("physicalswitch") > 0) {
- dst = dst.substring(0, dst.indexOf("physicalswitch") - 1);
- }
- return new ExternalTunnelKey(dst, src);
+ return existsFlag ;
}
logger.trace( "Wiring between source tunnel end points {}, destination tunnel end points {} " , srcte, dstte );
String interfaceName = srcte.getInterfaceName() ;
Class<? extends TunnelTypeBase> tunType = srcte.getTunnelType();
- String ifDescription = srcte.getTunnelType().getName();
+ String tunTypeStr = srcte.getTunnelType().getName();
// Form the trunk Interface Name
- String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName,srcte.getIpAddress().getIpv4Address().getValue(), dstte.getIpAddress().getIpv4Address().getValue()) ;
- IpAddress gwyIpAddress = ( srcte.getSubnetMask().equals(dstte.getSubnetMask()) ) ? null : srcte.getGwIpAddress() ;
+ String trunkInterfaceName = ItmUtils.getTrunkInterfaceName( idManagerService, interfaceName,
+ srcte.getIpAddress().getIpv4Address().getValue(),
+ dstte.getIpAddress().getIpv4Address().getValue(),
+ tunTypeStr) ;
+ IpAddress gatewayIpObj = new IpAddress("0.0.0.0".toCharArray());
+ IpAddress gwyIpAddress = ( srcte.getSubnetMask().equals(dstte.getSubnetMask()) ) ? gatewayIpObj : srcte.getGwIpAddress() ;
logger.debug( " Creating Trunk Interface with parameters trunk I/f Name - {}, parent I/f name - {}, source IP - {}, destination IP - {} gateway IP - {}",trunkInterfaceName, interfaceName, srcte.getIpAddress(), dstte.getIpAddress(), gwyIpAddress ) ;
- Interface iface = ItmUtils.buildTunnelInterface(srcDpnId, trunkInterfaceName,
- String.format("%s %s", ifDescription, "Trunk Interface"), true, tunType, srcte.getIpAddress(),
- dstte.getIpAddress(), gwyIpAddress, srcte.getVLANID(), true, false, null);
+ Boolean monitorEnabled = ItmUtils.readMonitoringStateFromDS(dataBroker);
+ Integer monitorInterval = ItmUtils.readMonitorIntervalfromDS(dataBroker);
+ if(monitorInterval == null)
+ monitorInterval = ITMConstants.DEFAULT_MONITOR_INTERVAL;
+ Interface iface = ItmUtils.buildTunnelInterface(srcDpnId, trunkInterfaceName, String.format( "%s %s",ItmUtils.convertTunnelTypetoString(srcte.getTunnelType()), "Trunk Interface"), true, tunType, srcte.getIpAddress(), dstte.getIpAddress(), gwyIpAddress, srcte.getVLANID(), true, monitorEnabled, monitorInterval*1000);
logger.debug( " Trunk Interface builder - {} ", iface ) ;
InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
logger.debug( " Trunk Interface Identifier - {} ", trunkIdentifier ) ;
logger.trace( " Writing Trunk Interface to Config DS {}, {} ", trunkIdentifier, iface ) ;
t.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, iface, true);
+ ItmUtils.itmCache.addInterface(iface);
// also update itm-state ds?
InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
TunnelList.class)
- .child(InternalTunnel.class, new InternalTunnelKey( dstDpnId,srcDpnId ));
- InternalTunnel tnl = ItmUtils.buildInternalTunnel(srcDpnId, dstDpnId, trunkInterfaceName);
+ .child(InternalTunnel.class, new InternalTunnelKey( dstDpnId, srcDpnId, tunType));
+ InternalTunnel tnl = ItmUtils.buildInternalTunnel(srcDpnId, dstDpnId, tunType, trunkInterfaceName);
//ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, tnl, dataBroker, DEFAULT_CALLBACK);
t.merge(LogicalDatastoreType.CONFIGURATION,path, tnl, true) ;
+ ItmUtils.itmCache.addInternalTunnel(tnl);
return true;
}
}
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.DpnEndpoints;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
}
for (DPNTEPsInfo srcDpn : dpnTepsList) {
logger.trace("Processing srcDpn " + srcDpn);
- List<TunnelEndPoints> meshedEndPtCache = new ArrayList<TunnelEndPoints>(srcDpn.getTunnelEndPoints()) ;
+ List<TunnelEndPoints> meshedEndPtCache = new ArrayList<TunnelEndPoints>(ItmUtils.getTEPsForDpn(srcDpn.getDPNID(), meshedDpnList)) ;
+ if(meshedEndPtCache == null ) {
+ logger.debug("No Tunnel End Point configured for this DPN {}", srcDpn.getDPNID());
+ continue ;
+ }
+ logger.debug( "Entries in meshEndPointCache {} ", meshedEndPtCache.size() );
for (TunnelEndPoints srcTep : srcDpn.getTunnelEndPoints()) {
logger.trace("Processing srcTep " + srcTep);
String srcTZone = srcTep.getTransportZone();
for (TunnelEndPoints dstTep : dstDpn.getTunnelEndPoints()) {
logger.trace("Processing dstTep " + dstTep);
if (dstTep.getTransportZone().equals(srcTZone)) {
- if( checkIfTrunkExists(dstDpn.getDPNID(), srcDpn.getDPNID(), dataBroker)) {
+ if( checkIfTrunkExists(dstDpn.getDPNID(), srcDpn.getDPNID(), srcTep.getTunnelType(),dataBroker)) {
// remove all trunk interfaces
logger.trace("Invoking removeTrunkInterface between source TEP {} , Destination TEP {} " ,srcTep , dstTep);
removeTrunkInterface(dataBroker, idManagerService, srcTep, dstTep, srcDpn.getDPNID(), dstDpn.getDPNID(), t, futures);
InstanceIdentifier.builder(DpnEndpoints.class).child(DPNTEPsInfo.class, srcDpn.getKey())
.child(TunnelEndPoints.class, srcTep.getKey()).build();
- logger.trace("Tep Removal from DPNTEPSINFO CONFIG DS " + srcTep);
+ logger.trace("Tep Removal of TEP {} from DPNTEPSINFO CONFIG DS with Key {} " + srcTep, srcTep.getKey());
t.delete(LogicalDatastoreType.CONFIGURATION, tepPath);
// remove the tep from the cache
meshedEndPtCache.remove(srcTep) ;
TunnelEndPoints srcTep, TunnelEndPoints dstTep, BigInteger srcDpnId, BigInteger dstDpnId,
WriteTransaction t, List<ListenableFuture<Void>> futures) {
String trunkfwdIfName =
- ItmUtils.getTrunkInterfaceName(idManagerService, srcTep.getInterfaceName(), srcTep.getIpAddress()
- .getIpv4Address().getValue(), dstTep.getIpAddress().getIpv4Address()
- .getValue());
+ ItmUtils.getTrunkInterfaceName( idManagerService, srcTep.getInterfaceName(),
+ srcTep.getIpAddress().getIpv4Address().getValue(),
+ dstTep.getIpAddress().getIpv4Address().getValue(),
+ srcTep.getTunnelType().getName());
logger.trace("Removing forward Trunk Interface " + trunkfwdIfName);
InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkfwdIfName);
logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS ", trunkfwdIfName, trunkIdentifier ) ;
t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
-
+ ItmUtils.itmCache.removeInterface(trunkfwdIfName);
// also update itm-state ds -- Delete the forward tunnel-interface from the tunnel list
InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
TunnelList.class)
- .child(InternalTunnel.class, new InternalTunnelKey( srcDpnId, dstDpnId));
+ .child(InternalTunnel.class, new InternalTunnelKey( dstDpnId, srcDpnId, srcTep.getTunnelType()));
t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
+ ItmUtils.itmCache.removeInternalTunnel(trunkfwdIfName);
// Release the Ids for the forward trunk interface Name
ItmUtils.releaseIdForTrunkInterfaceName(idManagerService,srcTep.getInterfaceName(), srcTep.getIpAddress()
.getIpv4Address().getValue(), dstTep.getIpAddress().getIpv4Address()
- .getValue() );
+ .getValue(), srcTep.getTunnelType().getName() );
String trunkRevIfName =
- ItmUtils.getTrunkInterfaceName(idManagerService, dstTep.getInterfaceName(), dstTep.getIpAddress()
- .getIpv4Address().getValue(), srcTep.getIpAddress().getIpv4Address()
- .getValue());
+ ItmUtils.getTrunkInterfaceName( idManagerService, dstTep.getInterfaceName(),
+ dstTep.getIpAddress().getIpv4Address().getValue(),
+ srcTep.getIpAddress().getIpv4Address().getValue(),
+ srcTep.getTunnelType().getName());
logger.trace("Removing Reverse Trunk Interface " + trunkRevIfName);
trunkIdentifier = ItmUtils.buildId(trunkRevIfName);
logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS ", trunkRevIfName, trunkIdentifier ) ;
// also update itm-state ds -- Delete the reverse tunnel-interface from the tunnel list
path = InstanceIdentifier.create(
TunnelList.class)
- .child(InternalTunnel.class, new InternalTunnelKey(dstDpnId, srcDpnId));
+ .child(InternalTunnel.class, new InternalTunnelKey(dstDpnId, srcDpnId, srcTep.getTunnelType()));
t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
// Release the Ids for the reverse trunk interface Name
ItmUtils.releaseIdForTrunkInterfaceName(idManagerService, dstTep.getInterfaceName(), dstTep.getIpAddress()
.getIpv4Address().getValue(), srcTep.getIpAddress().getIpv4Address()
- .getValue());
+ .getValue(),dstTep.getTunnelType().getName());
}
- private static boolean checkIfTrunkExists( BigInteger srcDpnId, BigInteger dstDpnId, DataBroker dataBroker) {
+ private static boolean checkIfTrunkExists(BigInteger srcDpnId, BigInteger dstDpnId, Class<? extends TunnelTypeBase> tunType, DataBroker dataBroker) {
boolean existsFlag = false ;
InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
TunnelList.class)
- .child(InternalTunnel.class, new InternalTunnelKey( srcDpnId, dstDpnId));
+ .child(InternalTunnel.class, new InternalTunnelKey( dstDpnId, srcDpnId, tunType));
Optional<InternalTunnel> internalTunnels = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,path, dataBroker) ;
if( internalTunnels.isPresent())
existsFlag = true ;
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.vpnservice.itm.confighelpers;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.vpnservice.itm.impl.ItmUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnelBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+/**
+ * Created by eanraju on 23-Mar-16.
+ */
+public class ItmMonitorIntervalWorker implements Callable<List<ListenableFuture<Void>>> {
+ private static final Logger logger = LoggerFactory.getLogger(ItmMonitorIntervalWorker.class) ;
+ private DataBroker dataBroker;
+ private String tzone;
+ private Integer interval;
+ private List<HwVtep> hwVteps;
+ private Boolean exists;
+
+ public ItmMonitorIntervalWorker(List<HwVtep> hwVteps,String tzone,Integer interval, DataBroker dataBroker, Boolean exists){
+ this.dataBroker = dataBroker;
+ this.tzone = tzone;
+ this.interval = interval;
+ this.hwVteps = hwVteps;
+ this.exists = exists;
+ logger.trace("ItmMonitorToggleWorker initialized with tzone {} and Interval {}",tzone,interval );
+ }
+
+ @Override public List<ListenableFuture<Void>> call() throws Exception {
+ List<ListenableFuture<Void>> futures = new ArrayList<>() ;
+ logger.debug("Invoking Tunnel Monitor Worker tzone = {} Interval= {}",tzone,interval );
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ toggleTunnelMonitoring(hwVteps,interval,tzone,t,exists);
+ futures.add(t.submit());
+ return futures;
+ }
+
+ private void toggleTunnelMonitoring(List<HwVtep> hwVteps,Integer interval, String tzone, WriteTransaction t,Boolean exists) {
+ //exists means hwVteps exist for this tzone
+
+ //List<String> TunnelList = ItmUtils.getTunnelsofTzone(hwVteps, tzone, dataBroker, exists);
+ List<String> TunnelList = ItmUtils.getInternalTunnelsofTzone(tzone,dataBroker);
+ if(TunnelList !=null &&!TunnelList.isEmpty()) {
+ for (String tunnel : TunnelList)
+ toggle(tunnel, interval,t);
+ }
+ }
+
+ private void toggle(String tunnelInterfaceName, Integer interval, WriteTransaction t) {
+ if (tunnelInterfaceName != null) {
+ logger.debug("tunnel {} will have monitor interval {}", tunnelInterfaceName, interval);
+ InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(tunnelInterfaceName);
+ IfTunnel tunnel = new IfTunnelBuilder().setMonitorInterval(interval.longValue() * 1000).build();
+ InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(tunnelInterfaceName))
+ .addAugmentation(IfTunnel.class, tunnel);
+ t.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, builder.build());
+ }
+ }
+}
+
+
--- /dev/null
+/*
+ * Copyright (c) 2015, 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.vpnservice.itm.confighelpers;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.vpnservice.itm.impl.ItmUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+/**
+ * Created by eanraju on 23-Mar-16.
+ */
+public class ItmMonitorToggleWorker implements Callable<List<ListenableFuture<Void>>> {
+ private static final Logger logger = LoggerFactory.getLogger(ItmMonitorToggleWorker.class) ;
+ private DataBroker dataBroker;
+ private String tzone;
+ private boolean enabled;
+ private List<HwVtep> hwVteps;
+ private Boolean exists;
+
+ public ItmMonitorToggleWorker(List<HwVtep> hwVteps,String tzone,boolean enabled, DataBroker dataBroker, Boolean exists){
+ this.dataBroker = dataBroker;
+ this.tzone = tzone;
+ this.enabled = enabled;
+ this.hwVteps = hwVteps;
+ this.exists = exists;
+ logger.trace("ItmMonitorToggleWorker initialized with tzone {} and toggleBoolean {}",tzone,enabled );
+ }
+
+ @Override public List<ListenableFuture<Void>> call() throws Exception {
+ List<ListenableFuture<Void>> futures = new ArrayList<>() ;
+ logger.debug("Invoking Tunnel Monitor Worker tzone = {} enabled {}",tzone,enabled );
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ toggleTunnelMonitoring(hwVteps,enabled,tzone,t,exists);
+ futures.add(t.submit());
+ return futures;
+ }
+
+ private void toggleTunnelMonitoring(List<HwVtep> hwVteps,Boolean enabled, String tzone, WriteTransaction t,Boolean exists) {
+ //exists means hwVteps exist for this tzone
+
+ List<String> TunnelList = ItmUtils.getTunnelsofTzone(hwVteps,tzone,dataBroker,exists);
+ if(TunnelList !=null &&!TunnelList.isEmpty()) {
+ for (String tunnel : TunnelList)
+ toggle(tunnel, enabled,t);
+ }
+ }
+
+ private void toggle(String tunnelInterfaceName, boolean enabled, WriteTransaction t) {
+ if(tunnelInterfaceName!=null) {
+ InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(tunnelInterfaceName);
+ IfTunnel tunnel = new IfTunnelBuilder().setMonitorEnabled(enabled).build();
+ InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(tunnelInterfaceName))
+ .addAugmentation(IfTunnel.class, tunnel);
+ t.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, builder.build());
+ }
+ }
+}
+
+
+
+
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.vpnservice.itm.impl;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
+
+public class ItmCache {
+ private ConcurrentHashMap<String, Interface> interfaces = null;
+ private ConcurrentHashMap<String, ExternalTunnel> externalTunnels = null;
+ private ConcurrentHashMap<String, InternalTunnel> internalTunnels = null;
+
+ public ItmCache() {
+ this.interfaces = new ConcurrentHashMap<>();
+ this.internalTunnels = new ConcurrentHashMap<>();
+ this.externalTunnels = new ConcurrentHashMap<>();
+ }
+
+ public void addInterface(Interface iface) {
+ this.interfaces.put(iface.getName(), iface);
+ }
+
+ public Interface getInterface(String name) {
+ return this.interfaces.get(name);
+ }
+
+ public Interface removeInterface(String name) {
+ return this.interfaces.remove(name);
+ }
+
+ public Collection<Interface> getAllInterfaces() {
+ return this.interfaces.values();
+ }
+
+ public void addExternalTunnel(ExternalTunnel tunnel) {
+ this.externalTunnels.put(tunnel.getTunnelInterfaceName(), tunnel);
+ }
+
+ public ExternalTunnel getExternalTunnel(String name) {
+ return this.externalTunnels.get(name);
+ }
+
+ public ExternalTunnel removeExternalTunnel(String name) {
+ return this.externalTunnels.remove(name);
+ }
+
+ public void addInternalTunnel(InternalTunnel tunnel) {
+ this.internalTunnels.put(tunnel.getTunnelInterfaceName(), tunnel);
+ }
+
+ public InternalTunnel getInternalTunnel(String name) {
+ return this.internalTunnels.get(name);
+ }
+
+ public InternalTunnel removeInternalTunnel(String name) {
+ return this.internalTunnels.remove(name);
+ }
+
+}
import org.opendaylight.vpnservice.itm.api.IITMProvider;
import org.opendaylight.vpnservice.itm.cli.TepCommandHelper;
import org.opendaylight.vpnservice.itm.globals.ITMConstants;
-import org.opendaylight.vpnservice.itm.impl.ItmUtils;
+import org.opendaylight.vpnservice.itm.listeners.InterfaceStateListener;
import org.opendaylight.vpnservice.itm.listeners.TransportZoneListener;
+import org.opendaylight.vpnservice.itm.listeners.TunnelMonitorChangeListener;
+import org.opendaylight.vpnservice.itm.listeners.TunnelMonitorIntervalListener;
import org.opendaylight.vpnservice.itm.listeners.VtepConfigSchemaListener;
+import org.opendaylight.vpnservice.itm.monitoring.ItmTunnelEventListener;
import org.opendaylight.vpnservice.itm.rpc.ItmManagerRpcService;
import org.opendaylight.vpnservice.itm.snd.ITMStatusMonitor;
import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.OdlInterfaceRpcService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.ItmRpcService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList ;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private NotificationService notificationService;
private TepCommandHelper tepCommandHelper;
private TransportZoneListener tzChangeListener;
+ private TunnelMonitorChangeListener tnlToggleListener;
+ private TunnelMonitorIntervalListener tnlIntervalListener;
private VtepConfigSchemaListener vtepConfigSchemaListener;
+ private InterfaceStateListener ifStateListener;
private RpcProviderRegistry rpcProviderRegistry;
private static final ITMStatusMonitor itmStatusMonitor = ITMStatusMonitor.getInstance();
+ private ItmTunnelEventListener itmStateListener;
static short flag = 0;
public ItmProvider() {
tzChangeListener = new TransportZoneListener(dataBroker, idManager) ;
itmRpcService = new ItmManagerRpcService(dataBroker, idManager);
vtepConfigSchemaListener = new VtepConfigSchemaListener(dataBroker);
+ this.ifStateListener = new InterfaceStateListener(dataBroker);
+ tnlToggleListener = new TunnelMonitorChangeListener(dataBroker);
+ tnlIntervalListener = new TunnelMonitorIntervalListener(dataBroker);
tepCommandHelper = new TepCommandHelper(dataBroker);
final BindingAwareBroker.RpcRegistration<ItmRpcService> rpcRegistration = getRpcProviderRegistry().addRpcImplementation(ItmRpcService.class, itmRpcService);
itmRpcService.setMdsalManager(mdsalManager);
tzChangeListener.setMdsalManager(mdsalManager);
tzChangeListener.setItmManager(itmManager);
tzChangeListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
+ tnlIntervalListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
+ tnlToggleListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
tepCommandHelper = new TepCommandHelper(dataBroker);
tepCommandHelper.setInterfaceManager(interfaceManager);
+ itmStateListener =new ItmTunnelEventListener(dataBroker);
createIdPool();
itmStatusMonitor.reportStatus("OPERATIONAL");
} catch (Exception e) {
if (tzChangeListener != null) {
tzChangeListener.close();
}
-
+ if (tnlIntervalListener != null) {
+ tnlIntervalListener.close();
+ }
+ if(tnlToggleListener!= null){
+ tnlToggleListener.close();
+ }
LOG.info("ItmProvider Closed");
}
tepCommandHelper.showTeps(itmManager.getTunnelMonitorEnabledFromConfigDS(),
itmManager.getTunnelMonitorIntervalFromConfigDS());
}
+ public void showState(TunnelList tunnels) {
+ if (tunnels != null)
+ tepCommandHelper.showState(tunnels, itmManager.getTunnelMonitorEnabledFromConfigDS());
+ else
+ LOG.debug("No tunnels available");
+ }
public void deleteVtep(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask,
String gatewayIp, String transportZone) {
this);
if (ItmUtils.getDpnIdList(schema.getDpnIds()) == null) {
VtepConfigSchemaBuilder builder = new VtepConfigSchemaBuilder(schema);
+ if (ItmUtils.getDpnIdList(schema.getDpnIds()).isEmpty()) {
builder.setDpnIds(schema.getDpnIds());
schema = builder.build();
} else {
if (lstDpnsForAdd != null && !lstDpnsForAdd.isEmpty()) {
- ItmUtils.getDpnIdList(schema.getDpnIds()).addAll(lstDpnsForAdd);
+ List<BigInteger> originalDpnList = ItmUtils.getDpnIdList(schema.getDpnIds()) ;
+ originalDpnList.addAll(lstDpnsForAdd) ;
+ builder.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(originalDpnList));
}
if (lstDpnsForDelete != null && !lstDpnsForDelete.isEmpty()) {
- ItmUtils.getDpnIdList(schema.getDpnIds()).removeAll(lstDpnsForDelete);
+ List<BigInteger> originalDpnList = ItmUtils.getDpnIdList(schema.getDpnIds()) ;
+ originalDpnList.removeAll(lstDpnsForAdd) ;
+ builder.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(originalDpnList)) ;
}
}
+ schema = builder.build();
MDSALUtil.syncWrite(this.dataBroker, LogicalDatastoreType.CONFIGURATION,
ItmUtils.getVtepConfigSchemaIdentifier(schemaName), schema);
LOG.debug("Vtep config schema {} updated to config DS with DPN's {}", schemaName, ItmUtils.getDpnIdList(schema.getDpnIds()));
}
-
+ }
/*
* (non-Javadoc)
*
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorEnabled;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorInterval;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.VtepConfigSchemas;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.VtepIpPools;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.vtep.config.schemas.VtepConfigSchema;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.interfaces._interface.NodeIdentifierKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.DpnEndpoints;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.DpnEndpointsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfoBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfoKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnels_state.StateTunnelListKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeGre;
import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
import org.opendaylight.vpnservice.itm.globals.ITMConstants;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.vtep.config.schemas.vtep.config.schema.DpnIds ;
//import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice._interface.service.rev150602._interface.service.info.ServiceInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.TransportZones;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.TransportZone;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.vtep.config.schemas.vtep.config.schema.DpnIdsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.vtep.config.schemas.vtep.config.schema.DpnIdsKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.vtep.config.schemas.vtep.config.schema.DpnIds;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.TransportZoneKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.Subnets;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.subnets.Vteps;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
public static final String TUNNEL_TYPE_VXLAN = "VXLAN";
public static final String TUNNEL_TYPE_GRE = "GRE";
public static final String TUNNEL = "TUNNEL";
+ public static ItmCache itmCache = new ItmCache();
private static final Logger LOG = LoggerFactory.getLogger(ItmUtils.class);
return dpnId;
}
- public static String getTrunkInterfaceName(IdManagerService idManager, String parentInterfaceName, String localHostName, String remoteHostName) {
- String trunkInterfaceName = String.format("%s:%s:%s", parentInterfaceName, localHostName, remoteHostName);
+ public static String getTrunkInterfaceName(IdManagerService idManager, String parentInterfaceName,
+ String localHostName, String remoteHostName, String tunnelType) {
+ String tunnelTypeStr;
+ if(tunnelType.contains("TunnelTypeGre")) {
+ tunnelTypeStr = ITMConstants.TUNNEL_TYPE_GRE;
+ } else {
+ tunnelTypeStr = ITMConstants.TUNNEL_TYPE_VXLAN;
+ }
+ String trunkInterfaceName = String.format( "%s:%s:%s:%s", parentInterfaceName, localHostName,
+ remoteHostName, tunnelTypeStr);
+ LOG.trace("trunk interface name is {}", trunkInterfaceName);
trunkInterfaceName = String.format("%s:%s", TUNNEL, getUniqueId(idManager, trunkInterfaceName));
return trunkInterfaceName;
}
- public static void releaseIdForTrunkInterfaceName(IdManagerService idManager, String parentInterfaceName, String localHostName, String remoteHostName) {
- String trunkInterfaceName = String.format("%s:%s:%s", parentInterfaceName, localHostName, remoteHostName);
+ public static void releaseIdForTrunkInterfaceName(IdManagerService idManager, String parentInterfaceName, String localHostName, String remoteHostName, String tunnelType) {
+ String tunnelTypeStr;
+ if(tunnelType.contains("TunnelTypeGre")) {
+ tunnelTypeStr = ITMConstants.TUNNEL_TYPE_GRE;
+ } else {
+ tunnelTypeStr = ITMConstants.TUNNEL_TYPE_VXLAN;
+ }
+ String trunkInterfaceName = String.format("%s:%s:%s:%s", parentInterfaceName, localHostName, remoteHostName, tunnelTypeStr);
LOG.trace("Releasing Id for trunkInterface - {}", trunkInterfaceName );
releaseId(idManager, trunkInterfaceName) ;
}
public static InstanceIdentifier<DPNTEPsInfo> getDPNTEPInstance(BigInteger dpIdKey) {
InstanceIdentifier.InstanceIdentifierBuilder<DPNTEPsInfo> dpnTepInfoBuilder =
- InstanceIdentifier.builder(DpnEndpoints.class).child(DPNTEPsInfo.class, new DPNTEPsInfoKey(dpIdKey));
+ InstanceIdentifier.builder(DpnEndpoints.class).child(DPNTEPsInfo.class,
+ new DPNTEPsInfoKey(dpIdKey));
InstanceIdentifier<DPNTEPsInfo> dpnInfo = dpnTepInfoBuilder.build();
return dpnInfo;
}
public static TunnelEndPoints createTunnelEndPoints(BigInteger dpnId, IpAddress ipAddress, String portName, int vlanId,
IpPrefix prefix, IpAddress gwAddress, String zoneName, Class<? extends TunnelTypeBase> tunnel_type) {
// when Interface Mgr provides support to take in Dpn Id
- return new TunnelEndPointsBuilder().setKey(new TunnelEndPointsKey(ipAddress, portName, vlanId))
+ return new TunnelEndPointsBuilder().setKey(new TunnelEndPointsKey(ipAddress, portName,tunnel_type, vlanId))
.setSubnetMask(prefix).setGwIpAddress(gwAddress).setTransportZone(zoneName)
.setInterfaceName(ItmUtils.getInterfaceName(dpnId, portName, vlanId)).setTunnelType(tunnel_type).build();
}
}
public static Interface buildTunnelInterface(BigInteger dpn, String ifName, String desc, boolean enabled, Class<? extends TunnelTypeBase> tunType,
- IpAddress localIp, IpAddress remoteIp, IpAddress gatewayIp,Integer vlanId, boolean internal, boolean monitorEnabled, Long monitorInterval) {
+ IpAddress localIp, IpAddress remoteIp, IpAddress gatewayIp,Integer vlanId, boolean internal, Boolean monitorEnabled, Integer monitorInterval) {
InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(ifName)).setName(ifName)
.setDescription(desc).setEnabled(enabled).setType(Tunnel.class);
ParentRefs parentRefs = new ParentRefsBuilder().setDatapathNodeIdentifier(dpn).build();
IfL2vlan l2vlan = new IfL2vlanBuilder().setVlanId(new VlanId(vlanId)).build();
builder.addAugmentation(IfL2vlan.class, l2vlan);
}
- //use default monitoring value from Global Constants
- Long monitoringInterval = 10000L;
+ Long monitoringInterval = (long) ITMConstants.DEFAULT_MONITOR_INTERVAL;
+ Boolean monitoringEnabled = true;
if(monitorInterval!= null)
- monitoringInterval = monitorInterval;
- IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(remoteIp).setTunnelGateway(gatewayIp).setTunnelSource(localIp)
- .setTunnelInterfaceType(tunType).setInternal(internal).setMonitorEnabled(monitorEnabled).setMonitorInterval(monitoringInterval).build();
+ monitoringInterval = monitorInterval.longValue();
+ if(monitorEnabled!=null )
+ monitoringEnabled = monitorEnabled;
+ IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(remoteIp).setTunnelGateway(
+ gatewayIp).setTunnelSource(localIp)
+ .setTunnelInterfaceType(tunType).setInternal(internal).setMonitorEnabled(
+ monitoringEnabled).setMonitorInterval(monitoringInterval).build();
builder.addAugmentation(IfTunnel.class, tunnel);
return builder.build();
}
- public static Interface buildHwTunnelInterface(String tunnelIfName, String desc , boolean enabled, String topo_id, String node_id,
- Class<? extends TunnelTypeBase> tunType, IpAddress srcIp , IpAddress destIp, IpAddress gWIp,
- boolean monitor_enabled
- ){
- InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(tunnelIfName)).setName(tunnelIfName).setDescription(desc).
+ public static Interface buildHwTunnelInterface(String tunnelIfName, String desc, boolean enabled, String topo_id,
+ String node_id, Class<? extends TunnelTypeBase> tunType, IpAddress srcIp, IpAddress destIp,
+ IpAddress gWIp, Boolean monitor_enabled, Integer monitor_interval){
+ InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(tunnelIfName)).setName(
+ tunnelIfName).setDescription(desc).
setEnabled(enabled).setType(Tunnel.class);
List<NodeIdentifier> nodeIds = new ArrayList<NodeIdentifier>();
NodeIdentifier hWnode = new NodeIdentifierBuilder().setKey(new NodeIdentifierKey(topo_id)).setTopologyId(
nodeIds.add(hWnode);
ParentRefs parent = new ParentRefsBuilder().setNodeIdentifier(nodeIds).build();
builder.addAugmentation(ParentRefs.class , parent);
+ Long monitoringInterval = (long) ITMConstants.DEFAULT_MONITOR_INTERVAL;
+ Boolean monitoringEnabled = true;
+ if(monitor_interval!= null)
+ monitoringInterval = monitor_interval.longValue();
+ if(monitor_enabled!=null )
+ monitoringEnabled = monitor_enabled;
IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(destIp).setTunnelGateway(gWIp).setTunnelSource(
- srcIp).setMonitorEnabled(monitor_enabled).setTunnelInterfaceType(tunType).setInternal(false).build();
+ srcIp).setMonitorEnabled(monitoringEnabled).setMonitorInterval(100L).
+ setTunnelInterfaceType(tunType).setInternal(false).build();
builder.addAugmentation(IfTunnel.class, tunnel);
LOG.trace("iftunnel {} built from hwvtep {} ",tunnel,node_id);
return builder.build();
}
- public static InternalTunnel buildInternalTunnel( BigInteger srcDpnId, BigInteger dstDpnId, String trunkInterfaceName) {
- InternalTunnel tnl = new InternalTunnelBuilder().setKey(new InternalTunnelKey(dstDpnId,srcDpnId)).setDestinationDPN(dstDpnId)
- .setSourceDPN(srcDpnId)
+ public static InternalTunnel buildInternalTunnel( BigInteger srcDpnId, BigInteger dstDpnId,
+ Class<? extends TunnelTypeBase> tunType,
+ String trunkInterfaceName) {
+ InternalTunnel tnl = new InternalTunnelBuilder().setKey(new InternalTunnelKey(dstDpnId, srcDpnId, tunType)).setDestinationDPN(dstDpnId)
+ .setSourceDPN(srcDpnId).setTransportType(tunType)
.setTunnelInterfaceName(trunkInterfaceName).build();
return tnl ;
}
- public static ExternalTunnel buildExternalTunnel(String srcNode, String dstNode, String trunkInterfaceName) {
+ public static ExternalTunnel buildExternalTunnel(String srcNode, String dstNode,
+ Class<? extends TunnelTypeBase> tunType,
+ String trunkInterfaceName) {
ExternalTunnel extTnl = new ExternalTunnelBuilder().setKey(
- new ExternalTunnelKey(dstNode, srcNode)).setSourceDevice(srcNode).setDestinationDevice(dstNode).setTunnelInterfaceName(trunkInterfaceName).build();
+ new ExternalTunnelKey(dstNode, srcNode, tunType))
+ .setSourceDevice(srcNode).setDestinationDevice(dstNode)
+ .setTunnelInterfaceName(trunkInterfaceName)
+ .setTransportType(tunType).build();
return extTnl ;
}
return dpnIdList;
}
+ public static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> buildStateInterfaceId(String interfaceName) {
+ InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> idBuilder =
+ InstanceIdentifier.builder(InterfacesState.class)
+ .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.class,
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey(
+ interfaceName));
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> id = idBuilder.build();
+ return id;
+}
+ public static Boolean readMonitoringStateFromDS(DataBroker dataBroker) {
+ InstanceIdentifier<TunnelMonitorEnabled> iid = InstanceIdentifier.create(TunnelMonitorEnabled.class);
+ Optional<TunnelMonitorEnabled> tunnelMonitorEnabledOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
+ iid, dataBroker);
+ if(tunnelMonitorEnabledOptional.isPresent())
+ return tunnelMonitorEnabledOptional.get().isEnabled();
+ return null;
+ }
+
+ public static Integer readMonitorIntervalfromDS(DataBroker dataBroker) {
+ InstanceIdentifier<TunnelMonitorInterval> iid = InstanceIdentifier.create(TunnelMonitorInterval.class);
+ Optional<TunnelMonitorInterval> tunnelMonitorIOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, iid, dataBroker);
+ if(tunnelMonitorIOptional.isPresent())
+ return tunnelMonitorIOptional.get().getInterval();
+ return null;
+ }
+ public static List<String> getTunnelsofTzone(List<HwVtep> hwVteps, String tzone, DataBroker dataBroker, Boolean hwVtepsExist) {
+ List<String> tunnels = new ArrayList<String>();
+ InstanceIdentifier<TransportZone> path = InstanceIdentifier.builder(TransportZones.class).
+ child(TransportZone.class, new TransportZoneKey(tzone)).build();
+ Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
+ Class<? extends TunnelTypeBase> tunType = tZoneOptional.get().getTunnelType();
+ if (tZoneOptional.isPresent()) {
+ if (tZoneOptional.get().getSubnets() != null && !tZoneOptional.get().getSubnets().isEmpty()) {
+ for (Subnets sub : tZoneOptional.get().getSubnets()) {
+ if (sub.getVteps() != null && !sub.getVteps().isEmpty()) {
+ for (Vteps vtepLocal : sub.getVteps()) {
+ for (Vteps vtepRemote : sub.getVteps()) {
+ if (!vtepLocal.equals(vtepRemote)) {
+ InternalTunnelKey key = new InternalTunnelKey(vtepRemote.getDpnId(), vtepLocal.getDpnId(), tunType);
+ InstanceIdentifier<InternalTunnel> intIID =
+ InstanceIdentifier.builder(TunnelList.class).
+ child(InternalTunnel.class, key).build();
+ Optional<InternalTunnel> TunnelsOptional =
+ ItmUtils.read(LogicalDatastoreType.CONFIGURATION, intIID, dataBroker);
+ if (TunnelsOptional.isPresent()) {
+ LOG.trace("Internal Tunnel added {}",TunnelsOptional.get().getTunnelInterfaceName());
+ tunnels.add(TunnelsOptional.get().getTunnelInterfaceName());
+ }
+ }
+ }
+ if(hwVteps!= null && !hwVteps.isEmpty()) {
+ for (HwVtep hwVtep : hwVteps) {
+ tunnels.add(getExtTunnel(hwVtep.getNode_id(), vtepLocal.getDpnId().toString(),
+ tunType, dataBroker));
+ tunnels.add(getExtTunnel(vtepLocal.getDpnId().toString(), hwVtep.getNode_id(),
+ tunType, dataBroker));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if (hwVtepsExist) {
+ for (HwVtep hwVtep : hwVteps) {
+ for (HwVtep hwVtepOther : hwVteps) {
+ if (!hwVtep.getHwIp().equals(hwVtepOther.getHwIp())) {
+ tunnels.add(getExtTunnel(hwVtep.getNode_id(), hwVtepOther.getNode_id(), tunType, dataBroker));
+ tunnels.add(getExtTunnel(hwVtepOther.getNode_id(), hwVtep.getNode_id(), tunType, dataBroker));
+ }
+ }
+ }
+ }
+ return tunnels;
+ }
+ public static List<String> getInternalTunnelsofTzone(String tzone, DataBroker dataBroker) {
+ List<String> tunnels = new ArrayList<String>();
+ LOG.trace("Getting internal tunnels of {}",tzone);
+ InstanceIdentifier<TransportZone> path = InstanceIdentifier.builder(TransportZones.class).
+ child(TransportZone.class, new TransportZoneKey(tzone)).build();
+ Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
+ if (tZoneOptional.isPresent()) {
+ if (tZoneOptional.get().getSubnets() != null && !tZoneOptional.get().getSubnets().isEmpty()) {
+ for (Subnets sub : tZoneOptional.get().getSubnets()) {
+ if (sub.getVteps() != null && !sub.getVteps().isEmpty()) {
+ for (Vteps vtepLocal : sub.getVteps()) {
+ for (Vteps vtepRemote : sub.getVteps()) {
+ if (!vtepLocal.equals(vtepRemote)) {
+ InternalTunnelKey key = new InternalTunnelKey(vtepRemote.getDpnId(), vtepLocal.getDpnId(), tZoneOptional.get().getTunnelType());
+ InstanceIdentifier<InternalTunnel> intIID =
+ InstanceIdentifier.builder(TunnelList.class).
+ child(InternalTunnel.class, key).build();
+ Optional<InternalTunnel> TunnelsOptional =
+ ItmUtils.read(LogicalDatastoreType.CONFIGURATION, intIID, dataBroker);
+ if (TunnelsOptional.isPresent()) {
+ LOG.trace("Internal Tunnel added {}",
+ TunnelsOptional.get().getTunnelInterfaceName());
+ tunnels.add(TunnelsOptional.get().getTunnelInterfaceName());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return tunnels;
+ }
+ private static String getExtTunnel(String node_id, String dpId,Class<? extends TunnelTypeBase> tunType, DataBroker dataBroker) {
+ LOG.trace("getting ext tunnel for {} and dpId {}",node_id,dpId);
+ ExternalTunnelKey key = getExternalTunnelKey(dpId,node_id, tunType);
+ InstanceIdentifier<ExternalTunnel> intIID = InstanceIdentifier.builder(ExternalTunnelList.class).
+ child(ExternalTunnel.class, key).build();
+ Optional<ExternalTunnel> TunnelsOptional =
+ ItmUtils.read(LogicalDatastoreType.CONFIGURATION, intIID, dataBroker);
+ if (TunnelsOptional.isPresent()) {
+ LOG.trace("ext tunnel returned {} ",TunnelsOptional.get().getTunnelInterfaceName());
+ return TunnelsOptional.get().getTunnelInterfaceName();
+ }
+ return null;
+ }
+ public static ExternalTunnelKey getExternalTunnelKey(String dst , String src, Class<? extends TunnelTypeBase> tunType) {
+ if (src.indexOf("physicalswitch") > 0) {
+ src = src.substring(0, src.indexOf("physicalswitch") - 1);
+ }
+ if (dst.indexOf("physicalswitch") > 0) {
+ dst = dst.substring(0, dst.indexOf("physicalswitch") - 1);
+ }
+ return new ExternalTunnelKey(dst, src, tunType);
+ }
+ public static List<TunnelEndPoints> getTEPsForDpn( BigInteger srcDpn, List<DPNTEPsInfo> dpnList) {
+ for (DPNTEPsInfo dpn : dpnList) {
+ if( dpn.getDPNID().equals(srcDpn)) {
+ return dpn.getTunnelEndPoints() ;
+ }
+ }
+ return null ;
+ }
+ public static TunnelList getAllInternalTunnels(DataBroker broker) {
+ InstanceIdentifier<TunnelList> tunnelListInstanceIdentifier = InstanceIdentifier.builder(TunnelList.class).build();
+ Optional<TunnelList> tunnelList = read(LogicalDatastoreType.CONFIGURATION, tunnelListInstanceIdentifier, broker);
+ if (tunnelList.isPresent()) {
+ return tunnelList.get();
+ }
+ return null;
+ }
+ public static InternalTunnel getInternalTunnel(String interfaceName, DataBroker broker) {
+ InternalTunnel internalTunnel = null;
+ TunnelList tunnelList = getAllInternalTunnels(broker);
+ if (tunnelList != null && tunnelList.getInternalTunnel() != null) {
+ List<InternalTunnel> internalTunnels = tunnelList.getInternalTunnel();
+ for (InternalTunnel tunnel : internalTunnels) {
+ if (tunnel.getTunnelInterfaceName().equalsIgnoreCase(interfaceName)) {
+ internalTunnel = tunnel;
+ break;
+ }
+ }
+ }
+ return internalTunnel;
+ }
+ public static ExternalTunnel getExternalTunnel(String interfaceName, DataBroker broker) {
+ ExternalTunnel externalTunnel = null;
+ List<ExternalTunnel> externalTunnels = getAllExternalTunnels(broker);
+ for (ExternalTunnel tunnel : externalTunnels) {
+ if (StringUtils.equalsIgnoreCase(interfaceName, tunnel.getTunnelInterfaceName())) {
+ externalTunnel = tunnel;
+ break;
+ }
+ }
+ return externalTunnel;
+ }
+ public static List<ExternalTunnel> getAllExternalTunnels(DataBroker broker) {
+ List<ExternalTunnel> result = null;
+ InstanceIdentifier<ExternalTunnelList> id = InstanceIdentifier.builder(ExternalTunnelList.class).build();
+ Optional<ExternalTunnelList> tunnelList = read(LogicalDatastoreType.CONFIGURATION, id, broker);
+ if (tunnelList.isPresent()) {
+ result = tunnelList.get().getExternalTunnel();
+ }
+ if (result == null) {
+ result = Collections.emptyList();
+ }
+ return result;
+ }
+ public static String convertTunnelTypetoString(Class<? extends TunnelTypeBase> tunType ) {
+ String tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
+ if( tunType.equals(TunnelTypeVxlan.class))
+ tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN ;
+ else if( tunType.equals(TunnelTypeGre.class) )
+ tunnelType = ITMConstants.TUNNEL_TYPE_GRE ;
+ else if (tunnelType.equals(TunnelTypeMplsOverGre.class))
+ tunnelType = ITMConstants.TUNNEL_TYPE_MPLS_OVER_GRE;
+ return tunnelType ;
+ }
+ public static boolean isItmIfType(Class<? extends InterfaceType> ifType) {
+ if( (ifType != null) && (ifType.isAssignableFrom(Tunnel.class)) ) {
+ return true;
+ }
+ return false;
+ }
+ public static StateTunnelListKey getTunnelStateKey( org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface iface) {
+ StateTunnelListKey key = null;
+ if(isItmIfType(iface.getType())) {
+ key = new StateTunnelListKey(iface.getName());
+ }
+ return key;
+ }
+ public static void updateTunnelsCache(DataBroker broker) {
+ List<InternalTunnel> internalTunnels = getAllInternalTunnels(broker, LogicalDatastoreType.CONFIGURATION);
+ for (InternalTunnel tunnel : internalTunnels) {
+ itmCache.addInternalTunnel(tunnel);
+ }
+ List<ExternalTunnel> externalTunnels = getAllExternalTunnels(broker, LogicalDatastoreType.CONFIGURATION);
+ for (ExternalTunnel tunnel : externalTunnels) {
+ itmCache.addExternalTunnel(tunnel);
+ }
+ }
+ public static List<ExternalTunnel> getAllExternalTunnels(DataBroker dataBroker, LogicalDatastoreType datastoreType) {
+ List<ExternalTunnel> result = null;
+ InstanceIdentifier<ExternalTunnelList> iid = InstanceIdentifier.builder(ExternalTunnelList.class).build();
+ Optional<ExternalTunnelList> tunnelList = read(LogicalDatastoreType.CONFIGURATION, iid, dataBroker);
+ if (tunnelList.isPresent()) {
+ result = tunnelList.get().getExternalTunnel();
+ }
+ if (result == null) {
+ result = Collections.emptyList();
+ }
+ return result;
+ }
+ public static List<InternalTunnel> getAllInternalTunnels(DataBroker dataBroker, LogicalDatastoreType datastoreType) {
+ List<InternalTunnel> result = null;
+ InstanceIdentifier<TunnelList> iid = InstanceIdentifier.builder(TunnelList.class).build();
+ Optional<TunnelList> tunnelList = read(LogicalDatastoreType.CONFIGURATION, iid, dataBroker);
+ if (tunnelList.isPresent()) {
+ result = tunnelList.get().getInternalTunnel();
+ }
+ if (result == null) {
+ result = Collections.emptyList();
+ }
+ return result;
+ }
+ public static Interface getInterface(
+ String name, DataBroker broker) {
+ Interface result = itmCache.getInterface(name);
+ if (result == null) {
+ InstanceIdentifier<Interface> iid =
+ InstanceIdentifier.builder(Interfaces.class)
+ .child(Interface.class, new InterfaceKey(name)).build();
+ Optional<Interface> optInterface = read(LogicalDatastoreType.CONFIGURATION, iid, broker);
+ if (optInterface.isPresent()) {
+ result = optInterface.get();
+ itmCache.addInterface(result);
+ }
+ }
+ return result;
+ }
}
-
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.vpnservice.itm.listeners;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.vpnservice.itm.impl.ItmUtils;
+import org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TepTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TepTypeExternal;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TepTypeHwvtep;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TepTypeInternal;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelsState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnels_state.StateTunnelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnels_state.StateTunnelListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnels_state.StateTunnelListKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnels_state.state.tunnel.list.DstInfoBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnels_state.state.tunnel.list.SrcInfoBuilder;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.net.InetAddresses;
+
+public class InterfaceStateListener extends AbstractDataChangeListener<Interface> implements AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(InterfaceStateListener.class);
+
+ private ListenerRegistration<DataChangeListener> listenerRegistration;
+ private final DataBroker broker;
+
+ public InterfaceStateListener(final DataBroker db) {
+ super(Interface.class);
+ broker = db;
+ registerListener(db);
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (listenerRegistration != null) {
+ try {
+ listenerRegistration.close();
+ } catch (final Exception e) {
+ LOG.error("Error when cleaning up interface state listener", e);
+ }
+ listenerRegistration = null;
+ }
+ LOG.info("Interface state listener Closed");
+ }
+
+ private void registerListener(final DataBroker db) {
+ try {
+ listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+ getWildCardPath(), InterfaceStateListener.this, DataChangeScope.SUBTREE);
+ } catch (final Exception e) {
+ LOG.error("ITM Interfaces State listener registration fail!", e);
+ throw new IllegalStateException("ITM Interfaces State listener registration failed.", e);
+ }
+ }
+
+ private InstanceIdentifier<Interface> getWildCardPath() {
+ return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
+ }
+
+ @Override
+ protected void add(InstanceIdentifier<Interface> identifier, Interface iface) {
+ LOG.trace("Interface added: {}", iface);
+ if(ItmUtils.isItmIfType(iface.getType())) {
+ LOG.debug("Interface of type Tunnel added: {}", iface.getName());
+ updateItmState(iface);
+ }
+ }
+
+ @Override
+ protected void remove(InstanceIdentifier<Interface> identifier,
+ Interface iface) {
+ LOG.trace("Interface deleted: {}", iface);
+ if(ItmUtils.isItmIfType(iface.getType())) {
+ LOG.debug("Tunnel interface deleted: {}", iface.getName());
+ StateTunnelListKey tlKey = null;
+ tlKey = ItmUtils.getTunnelStateKey(iface);
+ InstanceIdentifier<StateTunnelList> stListId = buildStateTunnelListId(tlKey);
+ LOG.trace("Deleting tunnel_state for Id: {}", stListId);
+ ItmUtils.asyncDelete(LogicalDatastoreType.OPERATIONAL, stListId, broker, ItmUtils.DEFAULT_CALLBACK);
+ }
+ }
+
+ @Override
+ protected void update(InstanceIdentifier<Interface> identifier,
+ Interface original, Interface update) {
+ /*
+ * update contains only delta, may not include iftype
+ * Note: This assumes type can't be edited on the fly
+ */
+ if(ItmUtils.isItmIfType(original.getType())) {
+ LOG.trace("Interface updated. Old: {} New: {}", original, update);
+ OperStatus operStatus = update.getOperStatus();
+ if( operStatus != null ) {
+ LOG.debug("Tunnel Interface {} changed state to {}", original.getName(), operStatus);
+ updateItmState(update);
+ }
+ }
+ }
+
+ private void updateItmState(Interface iface) {
+ StateTunnelListKey tlKey = null;
+ tlKey = ItmUtils.getTunnelStateKey(iface);
+ LOG.trace("TunnelStateKey: {} for interface: {}", tlKey, iface.getName());
+ InstanceIdentifier<StateTunnelList> stListId = buildStateTunnelListId(tlKey);
+ Optional<StateTunnelList> tunnelsState = ItmUtils.read(LogicalDatastoreType.OPERATIONAL, stListId, broker);
+ StateTunnelList tunnelStateList;
+ StateTunnelListBuilder stlBuilder;
+ boolean tunnelState = (iface.getOperStatus().equals(OperStatus.Up)) ? (true):(false);
+ if(tunnelsState.isPresent()) {
+ tunnelStateList = tunnelsState.get();
+ stlBuilder = new StateTunnelListBuilder(tunnelStateList);
+ stlBuilder.setTunnelState(tunnelState);
+ StateTunnelList stList = stlBuilder.build();
+ LOG.trace("Updating tunnel_state: {} for Id: {}",stList, stListId);
+ ItmUtils.asyncUpdate(LogicalDatastoreType.OPERATIONAL, stListId, stList, broker, ItmUtils.DEFAULT_CALLBACK);
+ } else {
+ // Create new Tunnel State
+ try {
+ /*FIXME:
+ * A defensive try-catch to find issues without disrupting existing behavior.
+ */
+ tunnelStateList = buildStateTunnelList(tlKey, iface.getName(), tunnelState);
+ LOG.trace("Creating tunnel_state: {} for Id: {}", tunnelStateList, stListId);
+ ItmUtils.asyncUpdate(LogicalDatastoreType.OPERATIONAL, stListId, tunnelStateList, broker,
+ ItmUtils.DEFAULT_CALLBACK);
+ } catch (Exception e) {
+ LOG.warn("Exception trying to create tunnel state for {}", iface.getName(), e);
+ }
+ }
+ }
+
+ private StateTunnelList buildStateTunnelList(StateTunnelListKey tlKey, String name, boolean state) {
+ StateTunnelListBuilder stlBuilder = new StateTunnelListBuilder();
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
+ ItmUtils.getInterface(name, broker);
+ IfTunnel ifTunnel = iface.getAugmentation(IfTunnel.class);
+ ParentRefs parentRefs = iface.getAugmentation(ParentRefs.class);
+ if(ifTunnel == null && parentRefs == null) {
+ return null;
+ }
+ DstInfoBuilder dstInfoBuilder = new DstInfoBuilder();
+ SrcInfoBuilder srcInfoBuilder = new SrcInfoBuilder();
+ dstInfoBuilder.setTepIp(ifTunnel.getTunnelDestination());
+ srcInfoBuilder.setTepIp(ifTunnel.getTunnelSource());
+ //TODO: Add/Improve logic for device type
+ InternalTunnel internalTunnel = ItmUtils.itmCache.getInternalTunnel(name);
+ ExternalTunnel externalTunnel = ItmUtils.itmCache.getExternalTunnel(name);
+ if(internalTunnel == null && externalTunnel == null) {
+ // both not present in cache. let us update and try again.
+ ItmUtils.updateTunnelsCache(broker);
+ internalTunnel = ItmUtils.itmCache.getInternalTunnel(name);
+ externalTunnel = ItmUtils.itmCache.getExternalTunnel(name);
+ }
+ if(internalTunnel != null) {
+ srcInfoBuilder.setTepDeviceId(internalTunnel.getSourceDPN().toString()).setTepDeviceType(TepTypeInternal.class);
+ dstInfoBuilder.setTepDeviceId(internalTunnel.getDestinationDPN().toString())
+ .setTepDeviceType(TepTypeInternal.class);
+ stlBuilder.setTransportType(internalTunnel.getTransportType());
+ } else if(externalTunnel != null) {
+ ExternalTunnel tunnel = ItmUtils.itmCache.getExternalTunnel(name);
+ srcInfoBuilder.setTepDeviceId(tunnel.getSourceDevice())
+ .setTepDeviceType(getDeviceType(tunnel.getSourceDevice()));
+ dstInfoBuilder.setTepDeviceId(tunnel.getDestinationDevice())
+ .setTepDeviceType(getDeviceType(tunnel.getSourceDevice()))
+ .setTepIp(ifTunnel.getTunnelDestination());
+ stlBuilder.setTransportType(tunnel.getTransportType());
+ }
+ stlBuilder.setKey(tlKey).setTunnelInterfaceName(name).setTunnelState(state)
+ .setDstInfo(dstInfoBuilder.build()).setSrcInfo(srcInfoBuilder.build());
+ return stlBuilder.build();
+ }
+
+ private Class<? extends TepTypeBase> getDeviceType(String device) {
+ if(device.startsWith("hwvtep")) {
+ return TepTypeHwvtep.class;
+ } else if(InetAddresses.isInetAddress(device)) {
+ return TepTypeExternal.class;
+ } else {
+ return TepTypeInternal.class;
+ }
+ }
+
+ private InstanceIdentifier<StateTunnelList> buildStateTunnelListId(StateTunnelListKey tlKey) {
+ InstanceIdentifier<StateTunnelList> stListId =
+ InstanceIdentifier.builder(TunnelsState.class).child(StateTunnelList.class, tlKey).build();
+ return stListId;
+ }
+
+}
LOG.trace("Delete: Invoking deleteTunnels in ItmManager with DpnList {}", opDpnList);
if(opDpnList.size()>0 || hwVtepList.size()>0) {
LOG.trace("Delete: Invoking ItmManager");
- LOG.trace("Add: Invoking ItmManager with hwVtep List {} " , hwVtepList);
+ LOG.trace("Delete: Invoking ItmManager with hwVtep List {} " , hwVtepList);
// itmManager.deleteTunnels(opDpnList);
DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
ItmTepRemoveWorker removeWorker = new ItmTepRemoveWorker(opDpnList,hwVtepList, dataBroker, idManagerService, mdsalManager);
int vlanID = subnet.getVlanId();
LOG.trace("IpPrefix: {}, gatewayIP: {}, vlanID: {} ", ipPrefix, gatewayIP, vlanID);
List<Vteps> vtepsList = subnet.getVteps();
+ if(vtepsList!=null && !vtepsList.isEmpty()) {
for (Vteps vteps : vtepsList) {
BigInteger dpnID = vteps.getDpnId();
String port = vteps.getPortname();
IpAddress ipAddress = vteps.getIpAddress();
LOG.trace("DpnID: {}, port: {}, ipAddress: {}", dpnID, port, ipAddress);
- TunnelEndPoints tunnelEndPoints = ItmUtils.createTunnelEndPoints(dpnID, ipAddress, port, vlanID, ipPrefix, gatewayIP, zone_name, tunnel_type);
+ TunnelEndPoints tunnelEndPoints =
+ ItmUtils.createTunnelEndPoints(dpnID, ipAddress, port, vlanID, ipPrefix,
+ gatewayIP, zone_name, tunnel_type);
List<TunnelEndPoints> tunnelEndPointsList = mapDPNToTunnelEndpt.get(dpnID);
if (tunnelEndPointsList != null) {
LOG.trace("Existing DPN info list in the Map: {} ", dpnID);
tunnelEndPointsList = new ArrayList<TunnelEndPoints>();
tunnelEndPointsList.add(tunnelEndPoints);
mapDPNToTunnelEndpt.put(dpnID, tunnelEndPointsList);
+ }
}
}
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.vpnservice.itm.listeners;
+
+import com.google.common.base.Optional;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.vpnservice.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.vpnservice.datastoreutils.DataStoreJobCoordinator;
+import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
+import org.opendaylight.vpnservice.itm.confighelpers.HwVtep;
+import org.opendaylight.vpnservice.itm.confighelpers.ItmMonitorToggleWorker;
+import org.opendaylight.vpnservice.itm.confighelpers.ItmTepAddWorker;
+import org.opendaylight.vpnservice.itm.globals.ITMConstants;
+import org.opendaylight.vpnservice.itm.impl.ItmUtils;
+import org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.TransportZones;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.TransportZone;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.Subnets;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.subnets.DeviceVteps;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TunnelMonitorChangeListener extends AsyncDataTreeChangeListenerBase<TunnelMonitorEnabled, TunnelMonitorChangeListener>
+ implements AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(TunnelMonitorChangeListener.class);
+ private final DataBroker broker;
+ // private final IInterfaceManager interfaceManager;
+
+ public TunnelMonitorChangeListener(final DataBroker db) {
+ super(TunnelMonitorEnabled.class, TunnelMonitorChangeListener.class);
+ broker = db;
+ // interfaceManager = ifManager;
+ // registerListener(db);
+ }
+
+ /* private void registerListener(final DataBroker db) {
+ try {
+ TunnelMonitorChangeListener monitorEnabledChangeListener = new TunnelMonitorChangeListener();
+ monitorEnabledListenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
+ monitorEnabledChangeListener.getWildCardPath(), monitorEnabledChangeListener, DataChangeScope.SUBTREE);
+ } catch (final Exception e) {
+ LOG.error("ITM Monitor Interfaces DataChange listener registration fail!", e);
+ throw new IllegalStateException("ITM Monitor registration Listener failed.", e);
+ }
+ }
+*/ @Override
+ public void close() throws Exception {
+ /* if (monitorEnabledListenerRegistration != null) {
+ try {
+ monitorEnabledListenerRegistration.close();
+ } catch (final Exception e) {
+ LOG.error("Error when cleaning up DataChangeListener.", e);
+ }
+ monitorEnabledListenerRegistration = null;
+ }
+
+ if (monitorIntervalListenerRegistration != null) {
+ try {
+ monitorIntervalListenerRegistration.close();
+ } catch (final Exception e) {
+ LOG.error("Error when cleaning up DataChangeListener.", e);
+ }
+ monitorIntervalListenerRegistration = null;
+ }
+*/
+ LOG.info("Tunnel Monitor listeners Closed");
+ }
+
+ @Override protected InstanceIdentifier<TunnelMonitorEnabled> getWildCardPath() {
+ return InstanceIdentifier.create(TunnelMonitorEnabled.class);
+ }
+
+ @Override
+ protected void remove(InstanceIdentifier<TunnelMonitorEnabled> key, TunnelMonitorEnabled dataObjectModification) {
+ List<HwVtep> hwVteps = new ArrayList<HwVtep>();
+ Boolean hwVtepsExist = false;
+ DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
+ InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
+ Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, broker);
+ if (tZonesOptional.isPresent()) {
+ TransportZones tZones = tZonesOptional.get();
+ for (TransportZone tzone : tZones.getTransportZone()) {
+ hwVtepsExist = false;
+ hwVteps = new ArrayList<HwVtep>();
+ if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
+ for (Subnets sub : tzone.getSubnets()) {
+ if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
+ hwVtepsExist = true;
+ for (DeviceVteps deviceVtep : sub.getDeviceVteps()) {
+ HwVtep hwVtep = ItmUtils.createHwVtepObject(deviceVtep.getTopologyId(), deviceVtep.getNodeId(),
+ deviceVtep.getIpAddress(), sub.getPrefix(), sub.getGatewayIp(), sub.getVlanId(),
+ tzone.getTunnelType(), tzone);
+ hwVteps.add(hwVtep);
+ }
+ }
+ }
+ }
+ LOG.debug("Remove:Calling TunnelMonitorToggleWorker with tzone = {} and {}",tzone.getZoneName(),dataObjectModification.isEnabled());
+ ItmMonitorToggleWorker toggleWorker = new ItmMonitorToggleWorker(hwVteps, tzone.getZoneName(),
+ false, broker, hwVtepsExist);
+ coordinator.enqueueJob(tzone.getZoneName(), toggleWorker);
+ }
+ }
+ }
+
+
+ @Override protected void update(InstanceIdentifier<TunnelMonitorEnabled> key,
+ TunnelMonitorEnabled dataObjectModificationBefore,
+ TunnelMonitorEnabled dataObjectModificationAfter) {
+ LOG.debug("update TunnelMonitorChangeListener called with {}",dataObjectModificationAfter.isEnabled());
+ List<HwVtep> hwVteps = new ArrayList<HwVtep>();
+ Boolean hwVtepsExist = false;
+ DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
+ InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
+ Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, broker);
+ if (tZonesOptional.isPresent()) {
+ TransportZones tZones = tZonesOptional.get();
+ for (TransportZone tzone : tZones.getTransportZone()) {
+ hwVtepsExist = false;
+ hwVteps = new ArrayList<HwVtep>();
+ if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
+ for (Subnets sub : tzone.getSubnets()) {
+ if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
+ hwVtepsExist = true;//gets set to true only if this particular tzone has
+ LOG.debug("Update:Calling TunnelMonitorToggleWorker with tzone = {} and hwtepExist",tzone.getZoneName());
+ for (DeviceVteps deviceVtep : sub.getDeviceVteps()) {
+ HwVtep hwVtep = ItmUtils.createHwVtepObject(deviceVtep.getTopologyId(), deviceVtep.getNodeId(),
+ deviceVtep.getIpAddress(), sub.getPrefix(), sub.getGatewayIp(), sub.getVlanId(),
+ tzone.getTunnelType(), tzone);
+ hwVteps.add(hwVtep);
+ }
+ }
+ }
+ }
+ LOG.debug("Update:Calling TunnelMonitorToggleWorker with tzone = {} and {}",tzone.getZoneName(),dataObjectModificationAfter.isEnabled());
+ ItmMonitorToggleWorker toggleWorker = new ItmMonitorToggleWorker(hwVteps, tzone.getZoneName(),
+ dataObjectModificationAfter.isEnabled(), broker, hwVtepsExist);
+ coordinator.enqueueJob(tzone.getZoneName(), toggleWorker);
+ }
+ }
+ }
+
+ @Override
+ protected void add(InstanceIdentifier<TunnelMonitorEnabled> key, TunnelMonitorEnabled dataObjectModification) {
+ LOG.debug("add TunnelMonitorChangeListener called with {}",dataObjectModification.isEnabled());
+ List<HwVtep> hwVteps = new ArrayList<HwVtep>();
+ Boolean hwVtepsExist = false;
+ DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
+ InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
+ Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, broker);
+ if (tZonesOptional.isPresent()) {
+ TransportZones tZones = tZonesOptional.get();
+ for (TransportZone tzone : tZones.getTransportZone()) {
+ hwVtepsExist = false;
+ hwVteps = new ArrayList<HwVtep>();
+ if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
+ for (Subnets sub : tzone.getSubnets()) {
+ if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
+ hwVtepsExist = true;
+ for (DeviceVteps deviceVtep : sub.getDeviceVteps()) {
+ HwVtep hwVtep = ItmUtils.createHwVtepObject(deviceVtep.getTopologyId(), deviceVtep.getNodeId(),
+ deviceVtep.getIpAddress(), sub.getPrefix(), sub.getGatewayIp(), sub.getVlanId(),
+ tzone.getTunnelType(), tzone);
+ hwVteps.add(hwVtep);
+ }
+ }
+ }
+ }
+ LOG.debug("Add:Calling TunnelMonitorToggleWorker with tzone = {} and {}",tzone.getZoneName(),dataObjectModification.isEnabled());
+ ItmMonitorToggleWorker toggleWorker = new ItmMonitorToggleWorker(hwVteps, tzone.getZoneName(),
+ dataObjectModification.isEnabled(), broker, hwVtepsExist);
+ coordinator.enqueueJob(tzone.getZoneName(), toggleWorker);
+ }
+ }
+ }
+
+ @Override protected TunnelMonitorChangeListener getDataTreeChangeListener() {
+ return TunnelMonitorChangeListener.this;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.vpnservice.itm.listeners;
+
+import com.google.common.base.Optional;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.vpnservice.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.vpnservice.datastoreutils.DataStoreJobCoordinator;
+import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
+import org.opendaylight.vpnservice.itm.confighelpers.HwVtep;
+import org.opendaylight.vpnservice.itm.confighelpers.ItmMonitorIntervalWorker;
+import org.opendaylight.vpnservice.itm.confighelpers.ItmMonitorToggleWorker;
+import org.opendaylight.vpnservice.itm.confighelpers.ItmTepAddWorker;
+import org.opendaylight.vpnservice.itm.globals.ITMConstants;
+import org.opendaylight.vpnservice.itm.impl.ItmUtils;
+import org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorEnabled;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorInterval;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.TransportZones;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.TransportZone;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.Subnets;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.subnets.DeviceVteps;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TunnelMonitorIntervalListener extends AsyncDataTreeChangeListenerBase<TunnelMonitorInterval, TunnelMonitorIntervalListener>
+ implements AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(TunnelMonitorIntervalListener.class);
+ private ListenerRegistration<DataChangeListener> monitorIntervalListenerRegistration;
+ private final DataBroker broker;
+
+ public TunnelMonitorIntervalListener(DataBroker db) {
+ super(TunnelMonitorInterval.class, TunnelMonitorIntervalListener.class);
+ broker = db;
+ }
+
+ @Override protected InstanceIdentifier<TunnelMonitorInterval> getWildCardPath() {
+ return InstanceIdentifier.create(TunnelMonitorInterval.class);
+ }
+
+ @Override
+ protected void remove(InstanceIdentifier<TunnelMonitorInterval> key, TunnelMonitorInterval dataObjectModification) {
+ LOG.debug("remove TunnelMonitorIntervalListener called with {}",dataObjectModification.getInterval());
+ List<HwVtep> hwVteps = new ArrayList<HwVtep>();
+ Boolean hwVtepsExist = false;
+ DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
+ InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
+ Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, broker);
+ if (tZonesOptional.isPresent()) {
+ TransportZones tZones = tZonesOptional.get();
+ for (TransportZone tzone : tZones.getTransportZone()) {
+ /* hwVtepsExist = false;
+ hwVteps = new ArrayList<HwVtep>();
+ if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
+ for (Subnets sub : tzone.getSubnets()) {
+ if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
+ hwVtepsExist = true;
+ LOG.debug("Remove:Calling TunnelMonitorIntervalWorker with tzone = {} and hwtepExist",tzone.getZoneName());
+ for (DeviceVteps deviceVtep : sub.getDeviceVteps()) {
+ HwVtep hwVtep = ItmUtils.createHwVtepObject(deviceVtep.getTopologyId(), deviceVtep.getNodeId(),
+ deviceVtep.getIpAddress(), sub.getPrefix(), sub.getGatewayIp(), sub.getVlanId(),
+ tzone.getTunnelType(), tzone);
+ hwVteps.add(hwVtep);
+ }
+ }
+ }
+ }*/
+ //if you remove configuration, the last configured interval is only set i.e no change
+ LOG.debug("Remove:Calling TunnelMonitorIntervalWorker with tzone = {} and {}",tzone.getZoneName(),dataObjectModification.getInterval());
+ ItmMonitorIntervalWorker toggleWorker = new ItmMonitorIntervalWorker(hwVteps, tzone.getZoneName(),
+ dataObjectModification.getInterval(), broker, hwVtepsExist);
+ coordinator.enqueueJob(tzone.getZoneName(), toggleWorker);
+ }
+ }
+ }
+
+ @Override protected void update(InstanceIdentifier<TunnelMonitorInterval> key,
+ TunnelMonitorInterval dataObjectModificationBefore,
+ TunnelMonitorInterval dataObjectModificationAfter) {
+ LOG.debug("update TunnelMonitorIntervalListener called with {}",dataObjectModificationAfter.getInterval());
+ List<HwVtep> hwVteps = new ArrayList<HwVtep>();
+ Boolean hwVtepsExist = false;
+ DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
+ InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
+ Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, broker);
+ if (tZonesOptional.isPresent()) {
+ TransportZones tZones = tZonesOptional.get();
+ for (TransportZone tzone : tZones.getTransportZone()) {
+ /*hwVtepsExist = false;
+ hwVteps = new ArrayList<HwVtep>();
+ if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
+ for (Subnets sub : tzone.getSubnets()) {
+ if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
+ hwVtepsExist = true;//gets set to true only if this particular tzone has
+ LOG.debug("Update:Calling TunnelMonitorIntervalWorker with tzone = {} and hwtepExist",tzone.getZoneName());
+ for (DeviceVteps deviceVtep : sub.getDeviceVteps()) {
+ HwVtep hwVtep = ItmUtils.createHwVtepObject(deviceVtep.getTopologyId(), deviceVtep.getNodeId(),
+ deviceVtep.getIpAddress(), sub.getPrefix(), sub.getGatewayIp(), sub.getVlanId(),
+ tzone.getTunnelType(), tzone);
+ hwVteps.add(hwVtep);
+ }
+ }
+ }
+ }*/
+ LOG.debug("Update:Calling TunnelMonitorIntervalWorker with tzone = {} and {}",tzone.getZoneName(),dataObjectModificationAfter.getInterval());
+ ItmMonitorIntervalWorker intervalWorker = new ItmMonitorIntervalWorker(hwVteps, tzone.getZoneName(),
+ dataObjectModificationAfter.getInterval(), broker, hwVtepsExist);
+ coordinator.enqueueJob(tzone.getZoneName(), intervalWorker);
+ }
+ }
+ }
+
+ @Override
+ protected void add(InstanceIdentifier<TunnelMonitorInterval> key, TunnelMonitorInterval dataObjectModification) {
+ LOG.debug("Add TunnelMonitorIntervalListener called with {}",dataObjectModification.getInterval());
+ List<HwVtep> hwVteps = new ArrayList<HwVtep>();
+ Boolean hwVtepsExist = false;
+ DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
+ InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
+ Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, broker);
+ if (tZonesOptional.isPresent()) {
+ TransportZones tZones = tZonesOptional.get();
+ for (TransportZone tzone : tZones.getTransportZone()) {
+ /*hwVtepsExist = false;
+ hwVteps = new ArrayList<HwVtep>();
+ if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
+ for (Subnets sub : tzone.getSubnets()) {
+ if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
+ hwVtepsExist = true;
+ LOG.debug("Add:Calling TunnelMonitorIntervalWorker with tzone = {} and hwtepExist",tzone.getZoneName());
+ for (DeviceVteps deviceVtep : sub.getDeviceVteps()) {
+ HwVtep hwVtep = ItmUtils.createHwVtepObject(deviceVtep.getTopologyId(), deviceVtep.getNodeId(),
+ deviceVtep.getIpAddress(), sub.getPrefix(), sub.getGatewayIp(), sub.getVlanId(),
+ tzone.getTunnelType(), tzone);
+ hwVteps.add(hwVtep);
+ }
+ }
+ }
+ }*/
+ LOG.debug("Add:Calling TunnelMonitorIntervalWorker with tzone = {} and {}",tzone.getZoneName(),dataObjectModification.getInterval());
+ ItmMonitorIntervalWorker intervalWorker = new ItmMonitorIntervalWorker(hwVteps, tzone.getZoneName(),
+ dataObjectModification.getInterval(), broker, hwVtepsExist);
+ //conversion to milliseconds done while writing to i/f-mgr config DS
+ coordinator.enqueueJob(tzone.getZoneName(), intervalWorker);
+ }
+ }
+ }
+
+ @Override protected TunnelMonitorIntervalListener getDataTreeChangeListener() {
+ return TunnelMonitorIntervalListener.this;
+ }
+}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.vpnservice.itm.listeners;
import java.math.BigInteger;
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.vpnservice.itm.monitoring;
+
+import javax.management.AttributeChangeNotification;
+import javax.management.Notification;
+import javax.management.NotificationBroadcasterSupport;
+import java.util.ArrayList;
+
+/**
+ * Created by emnqrrw on 10/27/2015.
+ */
+public class DataPathAlarm extends NotificationBroadcasterSupport implements DataPathAlarmMBean {
+
+ ArrayList<String> raiseAlarmObject = new ArrayList<String>();
+ ArrayList<String> clearAlarmObject = new ArrayList<String>();
+ private long sequenceNumber = 1;
+
+ public void setRaiseAlarmObject(ArrayList<String> raiseAlarmObject) {
+ this.raiseAlarmObject = raiseAlarmObject;
+
+ Notification n = new AttributeChangeNotification(this,
+ sequenceNumber++, System.currentTimeMillis(),
+ "raise alarm object notified ", "raiseAlarmObject", "ArrayList",
+ "", this.raiseAlarmObject);
+ sendNotification(n);
+ }
+
+ public ArrayList<String> getRaiseAlarmObject() {
+ return raiseAlarmObject;
+ }
+
+ public void setClearAlarmObject(ArrayList<String> clearAlarmObject) {
+ this.clearAlarmObject = clearAlarmObject;
+
+ Notification n = new AttributeChangeNotification(this,
+ sequenceNumber++, System.currentTimeMillis(),
+ "clear alarm object notified ", "clearAlarmObject", "ArrayList",
+ "", this.clearAlarmObject);
+ sendNotification(n);
+ }
+
+ public ArrayList<String> getClearAlarmObject() {
+ return clearAlarmObject;
+ }
+
+ public synchronized void raiseAlarm(String alarmName, String additionalText, String source){
+ raiseAlarmObject.add(alarmName);
+ raiseAlarmObject.add(additionalText);
+ raiseAlarmObject.add(source);
+ setRaiseAlarmObject(raiseAlarmObject);
+ raiseAlarmObject.clear();
+ }
+ public synchronized void clearAlarm(String alarmName, String additionalText, String source){
+ clearAlarmObject.add(alarmName);
+ clearAlarmObject.add(additionalText);
+ clearAlarmObject.add(source);
+ setClearAlarmObject(clearAlarmObject);
+ clearAlarmObject.clear();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.vpnservice.itm.monitoring;
+
+import java.util.ArrayList;
+
+/**
+ * Created by emnqrrw on 10/27/2015.
+ */
+public interface DataPathAlarmMBean {
+ public void setRaiseAlarmObject(ArrayList<String> raiseAlarmObject);
+ public ArrayList<String> getRaiseAlarmObject();
+ public void setClearAlarmObject(ArrayList<String> clearAlarmObject);
+ public ArrayList<String> getClearAlarmObject();
+ public void raiseAlarm(String alarmName, String additionalText, String source);
+ public void clearAlarm(String alarmName, String additionalText, String source);
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.vpnservice.itm.monitoring;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+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.vpnservice.itm.impl.ItmUtils;
+import org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.math.BigInteger;
+
+/**
+ * Created by emnqrrw on 11/2/2015.
+ */
+public class ItmTunnelEventListener extends AbstractDataChangeListener<Interface> implements AutoCloseable {
+
+ private static final Logger logger = LoggerFactory.getLogger(ItmTunnelEventListener.class);
+ private final DataBroker broker;
+ private ListenerRegistration<DataChangeListener> listenerRegistration;
+ public static final JMXAlarmAgent alarmAgent = new JMXAlarmAgent();
+
+ public ItmTunnelEventListener(final DataBroker db){
+ super(Interface.class);
+ broker = db;
+ registerListener(db);
+ alarmAgent.registerMbean();
+ }
+
+ private void registerListener(final DataBroker db) {
+ try {
+ listenerRegistration = broker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+ getWildCardPath(), ItmTunnelEventListener.this, AsyncDataBroker.DataChangeScope.SUBTREE);
+ } catch (final Exception e) {
+ logger.error("ITM Monitor Interfaces DataChange listener registration fail!", e);
+ throw new IllegalStateException("ITM Monitor registration Listener failed.", e);
+ }
+ }
+
+ private InstanceIdentifier<Interface> getWildCardPath() {
+ return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
+ }
+
+ @Override
+ protected void remove(InstanceIdentifier<Interface> identifier, Interface del) {
+ String ifName = del.getName() ;
+ if( del.getType() != null && del.getType().equals(Tunnel.class)) {
+ InternalTunnel internalTunnel = ItmUtils.getInternalTunnel(ifName,broker);
+ if( internalTunnel != null) {
+ BigInteger srcDpId = internalTunnel.getSourceDPN();
+ BigInteger dstDpId = internalTunnel.getDestinationDPN();
+ String tunnelType = ItmUtils.convertTunnelTypetoString(internalTunnel.getTransportType());
+ logger.trace("ITM Tunnel removed b/w srcDpn: {} and dstDpn: {} for tunnelType: {}", srcDpId, dstDpId, tunnelType);
+ clearInternalDataPathAlarm(srcDpId.toString(),dstDpId.toString(),tunnelType);
+ }else {
+ ExternalTunnel externalTunnel = ItmUtils.getExternalTunnel(ifName,broker);
+ if( externalTunnel != null) {
+ String srcNode = externalTunnel.getSourceDevice();
+ String dstNode = externalTunnel.getDestinationDevice();
+ String tunnelType = ItmUtils.convertTunnelTypetoString(externalTunnel.getTransportType());
+ logger.trace("ITM Tunnel removed b/w srcNode: {} and dstNode: {} for tunnelType: {}", srcNode, dstNode, tunnelType);
+ clearExternalDataPathAlarm(srcNode,dstNode,tunnelType);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
+ String ifName = update.getName() ;
+ if( update.getType() != null && update.getType().equals(Tunnel.class)) {
+ InternalTunnel internalTunnel = ItmUtils.getInternalTunnel(ifName,broker);
+ if( internalTunnel != null) {
+ BigInteger srcDpId = internalTunnel.getSourceDPN();
+ BigInteger dstDpId = internalTunnel.getDestinationDPN();
+ String tunnelType = ItmUtils.convertTunnelTypetoString(internalTunnel.getTransportType());
+ logger.trace("ITM Tunnel state event changed from :{} to :{} for Tunnel Interface - {}", isTunnelInterfaceUp(original), isTunnelInterfaceUp(update), ifName);
+ if(isTunnelInterfaceUp(update)) {
+ logger.trace("ITM Tunnel State is UP b/w srcDpn: {} and dstDpn: {} for tunnelType {} ", srcDpId, dstDpId, tunnelType);
+ clearInternalDataPathAlarm(srcDpId.toString(),dstDpId.toString(),tunnelType);
+ }else {
+ logger.trace("ITM Tunnel State is DOWN b/w srcDpn: {} and dstDpn: {}", srcDpId, dstDpId);
+ StringBuilder alarmText = new StringBuilder();
+ alarmText.append("Data Path Connectivity is lost between ").append("openflow:").append(srcDpId).append(" and openflow:")
+ .append(dstDpId).append(" for tunnelType:").append(tunnelType);
+ raiseInternalDataPathAlarm(srcDpId.toString(), dstDpId.toString(), tunnelType,alarmText.toString());
+ }
+ }else{
+ ExternalTunnel externalTunnel = ItmUtils.getExternalTunnel(ifName,broker);
+ if( externalTunnel != null) {
+ String srcNode = externalTunnel.getSourceDevice();
+ String dstNode = externalTunnel.getDestinationDevice();
+ String tunnelType = ItmUtils.convertTunnelTypetoString(externalTunnel.getTransportType());
+ logger.trace("ITM Tunnel state event changed from :{} to :{} for Tunnel Interface - {}", isTunnelInterfaceUp(original), isTunnelInterfaceUp(update), ifName);
+ if(isTunnelInterfaceUp(update)) {
+ logger.trace("ITM Tunnel State is UP b/w srcNode: {} and dstNode: {} for tunnelType: {}", srcNode, dstNode, tunnelType);
+ clearExternalDataPathAlarm(srcNode.toString(),dstNode.toString(),tunnelType);
+ }else {
+ logger.trace("ITM Tunnel State is DOWN b/w srcNode: {} and dstNode: {}", srcNode, dstNode);
+ StringBuilder alarmText = new StringBuilder();
+ alarmText.append("Data Path Connectivity is lost between ").append(srcNode).append(dstNode).append(" for tunnelType:").append(tunnelType);
+ raiseExternalDataPathAlarm(srcNode, dstNode, tunnelType,alarmText.toString());
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void add(InstanceIdentifier<Interface> identifier, Interface add) {
+ String ifName = add.getName() ;
+ if( add.getType() != null && add.getType().equals(Tunnel.class)) {
+ InternalTunnel internalTunnel = ItmUtils.getInternalTunnel(ifName,broker);
+ if( internalTunnel != null) {
+ BigInteger srcDpId = internalTunnel.getSourceDPN();
+ BigInteger dstDpId = internalTunnel.getDestinationDPN();
+ String tunnelType = ItmUtils.convertTunnelTypetoString(internalTunnel.getTransportType());
+ if(!isTunnelInterfaceUp(add)) {
+ logger.trace("ITM Tunnel State during tep add is DOWN b/w srcDpn: {} and dstDpn: {} for tunnelType: {}", srcDpId, dstDpId, tunnelType);
+ StringBuilder alarmText = new StringBuilder();
+ alarmText.append("Data Path Connection is down between ").append("openflow:").append(srcDpId).append(" and openflow:")
+ .append(dstDpId).append(" for tunnelType:").append(tunnelType).append(" during initial state");
+ raiseInternalDataPathAlarm(srcDpId.toString(), dstDpId.toString(), tunnelType, alarmText.toString());
+ }
+ }else {
+ ExternalTunnel externalTunnel = ItmUtils.getExternalTunnel(ifName,broker);
+ if( externalTunnel != null) {
+ String srcNode = externalTunnel.getSourceDevice();
+ String dstNode = externalTunnel.getDestinationDevice();
+ String tunnelType = ItmUtils.convertTunnelTypetoString(externalTunnel.getTransportType());
+ if(!isTunnelInterfaceUp(add)) {
+ logger.trace("ITM Tunnel State during tep add is DOWN b/w srcNode: {} and dstNode: {} for tunnelType: {}", srcNode, dstNode, tunnelType);
+ StringBuilder alarmText = new StringBuilder();
+ alarmText.append("Data Path Connection is down between ").append(srcNode).append(dstNode).append(" for tunnelType:").append(tunnelType).append(" during initial state");
+ raiseExternalDataPathAlarm(srcNode, dstNode, tunnelType,alarmText.toString());
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (listenerRegistration != null) {
+ try {
+ listenerRegistration.close();
+ } catch (final Exception e) {
+ logger.error("Error when cleaning up DataChangeListener.", e);
+ }
+ listenerRegistration = null;
+ }
+ }
+
+ public void raiseInternalDataPathAlarm(String srcDpnId,String dstDpnId,String tunnelType,String alarmText) {
+
+ StringBuilder source = new StringBuilder();
+ source.append("srcDpn=openflow:").append(srcDpnId).append("-dstDpn=openflow:").append(dstDpnId).append("-tunnelType").append(tunnelType);
+
+ logger.trace("Raising DataPathConnectionFailure alarm... alarmText {} source {} ", alarmText, source);
+ //Invokes JMX raiseAlarm method
+ alarmAgent.invokeFMraisemethod("DataPathConnectionFailure", alarmText, source.toString());
+ }
+
+ public void clearInternalDataPathAlarm(String srcDpnId,String dstDpnId,String tunnelType) {
+ StringBuilder source = new StringBuilder();
+
+ source.append("srcDpn=openflow:").append(srcDpnId).append("-dstDpn=openflow:").append(dstDpnId).append("-tunnelType").append(tunnelType);
+ logger.trace("Clearing DataPathConnectionFailure alarm of source {} ", source);
+ //Invokes JMX clearAlarm method
+ alarmAgent.invokeFMclearmethod("DataPathConnectionFailure", "Clearing ITM Tunnel down alarm", source.toString());
+ }
+
+ public void raiseExternalDataPathAlarm(String srcDevice,String dstDevice,String tunnelType, String alarmText) {
+
+ StringBuilder source = new StringBuilder();
+ source.append("srcDevice=").append(srcDevice).append("-dstDevice=").append(dstDevice).append("-tunnelType").append(tunnelType);
+
+ logger.trace("Raising DataPathConnectionFailure alarm... alarmText {} source {} ", alarmText, source);
+ //Invokes JMX raiseAlarm method
+ alarmAgent.invokeFMraisemethod("DataPathConnectionFailure", alarmText, source.toString());
+ }
+
+
+ public void clearExternalDataPathAlarm(String srcDevice,String dstDevice,String tunnelType) {
+
+ StringBuilder source = new StringBuilder();
+
+ source.append("srcDevice=").append(srcDevice).append("-dstDevice=").append(dstDevice).append("-tunnelType").append(tunnelType);
+
+ //logger.trace("Clearing DataPathConnectionFailure alarm of source {} ", source);
+ //Invokes JMX clearAlarm method
+ alarmAgent.invokeFMclearmethod("DataPathConnectionFailure", "Clearing ITM Tunnel down alarm", source.toString());
+
+ }
+
+ private boolean isTunnelInterfaceUp( Interface intf) {
+ boolean interfaceUp = (intf.getOperStatus().equals(Interface.OperStatus.Up)) ? true :false ;
+ return interfaceUp ;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.vpnservice.itm.monitoring;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+/**
+ * Created by emnqrrw on 11/2/2015.
+ */
+public class JMXAlarmAgent {
+ static Logger s_logger = LoggerFactory.getLogger(JMXAlarmAgent.class);
+ private MBeanServer mbs = null;
+ private ObjectName alarmName = null;
+ private static final String BEANNAME = "SDNC.FM:name=DataPathAlarmBean";
+ private static DataPathAlarm alarmBean= new DataPathAlarm();
+
+ public JMXAlarmAgent() {
+ // Get the platform MBeanServer
+ mbs = ManagementFactory.getPlatformMBeanServer();
+ try {
+ alarmName = new ObjectName(BEANNAME);
+ } catch (MalformedObjectNameException e) {
+ s_logger.error("ObjectName instance creation failed for BEANAME {} : {}",BEANNAME, e);
+ }
+ }
+
+ public void registerMbean() {
+ // Unique identification of MBeans
+ try {
+ // Uniquely identify the MBeans and register them with the platform MBeanServer
+ if(!mbs.isRegistered(alarmName)) {
+ mbs.registerMBean(alarmBean, alarmName);
+ s_logger.debug("Registered Mbean {} successfully", alarmName);
+ }
+ } catch(Exception e) {
+ s_logger.error("Registeration failed for Mbean {} :{}", alarmName,e);
+ }
+ }
+
+ public void unregisterMbean() {
+ try {
+ if(mbs.isRegistered(alarmName)) {
+ mbs.unregisterMBean(alarmName);
+ s_logger.debug("Unregistered Mbean {} successfully", alarmName);
+ }
+ } catch (Exception e) {
+ s_logger.error("UnRegisteration failed for Mbean {} :{}", alarmName,e);
+ }
+ }
+
+ public void invokeFMraisemethod(String alarmId,String text,String src) {
+ try {
+ mbs.invoke(alarmName, "raiseAlarm", new Object[]{alarmId, text, src}, new String[]{String.class.getName(), String.class.getName(), String.class.getName()});
+ s_logger.trace("Invoked raiseAlarm function for Mbean {} with source {}", BEANNAME, src);
+ } catch (Exception e) {
+ s_logger.error("Invoking raiseAlarm method failed for Mbean {} :{}", alarmName,e);
+ }
+ }
+
+ public void invokeFMclearmethod(String alarmId,String text,String src) {
+ try {
+ mbs.invoke(alarmName, "clearAlarm", new Object[]{alarmId, text, src}, new String[]{String.class.getName(), String.class.getName(), String.class.getName()});
+ s_logger.trace("Invoked clearAlarm function for Mbean {} with source {}",BEANNAME,src);
+ } catch (Exception e) {
+ s_logger.error("Invoking clearAlarm method failed for Mbean {} :{}", alarmName,e);
+ }
+ }
+}
/*
- * Copyright (c) 2015, 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.vpnservice.mdsalutil.*;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeMplsOverGre;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.TransportZones;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.TransportZone;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.TransportZoneKey;
BigInteger destinationDpn = input.getDestinationDpid() ;
InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
TunnelList.class)
- .child(InternalTunnel.class, new InternalTunnelKey( destinationDpn,sourceDpn));
+ .child(InternalTunnel.class, new InternalTunnelKey(destinationDpn, sourceDpn, input.getTunnelType()));
Optional<InternalTunnel> tnl = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
String dstNode = input.getDestinationNode();
InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
ExternalTunnelList.class)
- .child(ExternalTunnel.class, new ExternalTunnelKey(dstNode, sourceNode));
+ .child(ExternalTunnel.class, new ExternalTunnelKey(dstNode, sourceNode, input.getTunnelType()));
Optional<ExternalTunnel> ext = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
LOG.info("create terminatingServiceAction on DpnId = {} for service id {} and instructions {}", input.getDpnId() , input.getServiceId(), input.getInstruction());
final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
int serviceId = input.getServiceId() ;
- List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
+ List<MatchInfo> mkMatches = getTunnelMatchesForServiceId(serviceId);
byte[] vxLANHeader = new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// Flags Byte
byte Flags = (byte) 0x08;
vxLANHeader[6] = (byte) (serviceId >> 0);
// Matching metadata
- mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {
- new BigInteger(1, vxLANHeader),
- MetaDataUtil.METADA_MASK_VALID_TUNNEL_ID_BIT_AND_TUNNEL_ID }));
+// mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {
+// new BigInteger(1, vxLANHeader),
+// MetaDataUtil.METADA_MASK_VALID_TUNNEL_ID_BIT_AND_TUNNEL_ID }));
Flow terminatingServiceTableFlow = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
getFlowRef(NwConstants.INTERNAL_TUNNEL_TABLE,serviceId), 5, String.format("%s:%d","ITM Flow Entry ",serviceId),
IpAddress dstIp = input.getDestinationIp() ;
InstanceIdentifier<ExternalTunnel> path1 = InstanceIdentifier.create(
ExternalTunnelList.class)
- .child(ExternalTunnel.class, new ExternalTunnelKey(String.valueOf(dstIp), srcDpn.toString()));
+ .child(ExternalTunnel.class, new ExternalTunnelKey(String.valueOf(dstIp), srcDpn.toString(), TunnelTypeMplsOverGre.class));
Optional<ExternalTunnel> ext = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path1, dataBroker);
if (dstIp.equals(firstEndPt.getIpAddress())) {
InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
TunnelList.class)
- .child(InternalTunnel.class, new InternalTunnelKey(teps.getDPNID(),srcDpn));
+ .child(InternalTunnel.class, new InternalTunnelKey(teps.getDPNID(), srcDpn, input.getTunnelType()));
Optional<InternalTunnel>
tnl =
}
});
}
+ else {
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No TransportZones configured").build());
+ return result;
+ }
return result;
} catch (Exception e) {
RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().
}
}
+ @Override
+ public Future<RpcResult<java.lang.Void>> addL2GwMlagDevice(AddL2GwMlagDeviceInput input)
+ {
+ final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
+ try {
+ final IpAddress hwIp = input.getIpAddress();
+ final List<String> node_id = input.getNodeId();
+ InstanceIdentifier<TransportZones> containerPath = InstanceIdentifier.create(TransportZones.class);
+ Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, containerPath, dataBroker);
+ if (tZonesOptional.isPresent()) {
+ TransportZones tZones = tZonesOptional.get();
+ if (tZones.getTransportZone() == null || tZones.getTransportZone().isEmpty()) {
+ LOG.error("No teps configured");
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No teps Configured").build());
+ return result;
+ }
+ String transportZone = tZones.getTransportZone().get(0).getZoneName();
+ if (tZones.getTransportZone().get(0).getSubnets() == null || tZones.getTransportZone().get(0).getSubnets().isEmpty()) {
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No subnets Configured").build());
+ return result;
+ }
+ SubnetsKey subnetsKey = tZones.getTransportZone().get(0).getSubnets().get(0).getKey();
+ DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, node_id.get(0));
+ InstanceIdentifier<DeviceVteps> path =
+ InstanceIdentifier.builder(TransportZones.class)
+ .child(TransportZone.class, new TransportZoneKey(transportZone))
+ .child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey).build();
+ DeviceVteps deviceVtep = new DeviceVtepsBuilder().setKey(deviceVtepKey).setIpAddress(hwIp).setNodeId(node_id.get(0)).setTopologyId(input.getTopologyId()).build();
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ LOG.trace("writing hWvtep{}",deviceVtep);
+ t.put(LogicalDatastoreType.CONFIGURATION, path, deviceVtep, true);
+ if(node_id.size() == 2) {
+ LOG.trace("second node-id {}",node_id.get(1));
+ DeviceVtepsKey deviceVtepKey2 = new DeviceVtepsKey(hwIp, node_id.get(1));
+ InstanceIdentifier<DeviceVteps> path2 = InstanceIdentifier.builder(TransportZones.class)
+ .child(TransportZone.class, new TransportZoneKey(transportZone))
+ .child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey2).build();
+ DeviceVteps deviceVtep2 = new DeviceVtepsBuilder().setKey(deviceVtepKey2).setIpAddress(hwIp).setNodeId(node_id.get(1))
+ .setTopologyId(input.getTopologyId()).build();
+ LOG.trace("writing {}",deviceVtep2);
+ t.put(LogicalDatastoreType.CONFIGURATION, path2, deviceVtep2, true);
+ }ListenableFuture<Void> futureCheck = t.submit();
+ Futures.addCallback(futureCheck, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(Void aVoid) {
+ result.set(RpcResultBuilder.<Void>success().build());
+ }
+ @Override
+ public void onFailure(Throwable error) {
+ String msg = String.format("Unable to write HwVtep {} to datastore", node_id);
+ LOG.error("Unable to write HwVtep {}, {} to datastore", node_id , hwIp);
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
+ }
+ });
+ }
+ return result;
+ } catch (Exception e) {
+ RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().
+ withError(RpcError.ErrorType.APPLICATION, "Adding l2 Gateway to DS Failed", e);
+ return Futures.immediateFuture(resultBuilder.build());
+ }
+ }
+ @Override
+ public Future<RpcResult<Void>> deleteL2GwMlagDevice(DeleteL2GwMlagDeviceInput input) {
+ final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
+ try {
+ final IpAddress hwIp = input.getIpAddress();
+ final List<String> node_id = input.getNodeId();
+ InstanceIdentifier<TransportZones> containerPath = InstanceIdentifier.create(TransportZones.class);
+ Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, containerPath, dataBroker);
+ if (tZonesOptional.isPresent()) {
+ TransportZones tZones = tZonesOptional.get();
+ if (tZones.getTransportZone() == null || tZones.getTransportZone().isEmpty()) {
+ LOG.error("No teps configured");
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No teps Configured").build());
+ return result;
+ }
+ String transportZone = tZones.getTransportZone().get(0).getZoneName();
+ if (tZones.getTransportZone().get(0).getSubnets() == null || tZones.getTransportZone().get(0).getSubnets().isEmpty()) {
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No subnets Configured").build());
+ return result;
+ }
+ SubnetsKey subnetsKey = tZones.getTransportZone().get(0).getSubnets().get(0).getKey();
+ DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, node_id.get(0));
+ InstanceIdentifier<DeviceVteps> path =
+ InstanceIdentifier.builder(TransportZones.class)
+ .child(TransportZone.class, new TransportZoneKey(transportZone))
+ .child(Subnets.class, subnetsKey).child(DeviceVteps.class,
+ deviceVtepKey).build();
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ t.delete(LogicalDatastoreType.CONFIGURATION, path);
+ DeviceVtepsKey deviceVtepKey2 = new DeviceVtepsKey(hwIp, node_id.get(1));
+ InstanceIdentifier<DeviceVteps> path2 =
+ InstanceIdentifier.builder(TransportZones.class)
+ .child(TransportZone.class, new TransportZoneKey(transportZone))
+ .child(Subnets.class, subnetsKey).child(DeviceVteps.class,
+ deviceVtepKey2).build();
+ t.delete(LogicalDatastoreType.CONFIGURATION, path2);
+ ListenableFuture<Void> futureCheck = t.submit();
+ Futures.addCallback(futureCheck, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(Void aVoid) {
+ result.set(RpcResultBuilder.<Void>success().build());
+ }
+ @Override
+ public void onFailure(Throwable error) {
+ String msg = String.format("Unable to write HwVtep {} to datastore", node_id);
+ LOG.error("Unable to write HwVtep {}, {} to datastore", node_id , hwIp);
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
+ }
+ });
+ }
+ return result;
+ } catch (Exception e) {
+ RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().
+ withError(RpcError.ErrorType.APPLICATION, "Deleting l2 Gateway to DS Failed", e);
+ return Futures.immediateFuture(resultBuilder.build());
+ }
+ }
}
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
@Override
public java.lang.AutoCloseable createInstance() {
- ItmProvider provider = new ItmProvider();
+ ItmProvider provider = new ItmProvider();
provider.setMdsalApiManager(getMdsalutilDependency());
provider.setNotificationPublishService(getNotificationPublishServiceDependency());
provider.setNotificationService(getNotificationServiceDependency());
--- /dev/null
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+ <reference id="itmProviderRef" interface="org.opendaylight.vpnservice.itm.api.IITMProvider" availability="optional" />
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.TepAdd">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.TepDelete">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.TepShow">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.TepCommit">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.TepShowState">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.TepConfigureTunnelType">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.TepMonitor">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.TepDeleteDatastore">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.VtepSchemaAdd">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.VtepSchemaShow">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.VtepSchemaUpdate">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.VtepSchemaDelete">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.vpnservice.itm.cli.TepEnableTunnelMonitor">
+ <property name="itmProvider" ref="itmProviderRef" />
+ </action>
+ </command>
+ </command-bundle>
+</blueprint>
\ No newline at end of file