+
+ VpnInterface getVpnInterface(String interfaceName) {
+ Optional<VpnInterfaces> optVpnInterfaces = read(LogicalDatastoreType.CONFIGURATION, VpnUtil.getVpnInterfacesIdentifier());
+ if(optVpnInterfaces.isPresent()) {
+ List<VpnInterface> interfaces = optVpnInterfaces.get().getVpnInterface();
+ for(VpnInterface intf : interfaces) {
+ if(intf.getName().equals(interfaceName)) {
+ return intf;
+ }
+ }
+ }
+ return null;
+ }
+
+ private Interface getInterface(String interfaceName) {
+ Optional<Interface> optInterface = read(LogicalDatastoreType.CONFIGURATION, VpnUtil.getInterfaceIdentifier(interfaceName));
+ if(optInterface.isPresent()) {
+ return optInterface.get();
+ }
+ return null;
+ }
+
+ private String getTunnelInterfaceFlowRef(BigInteger dpnId, short tableId, String ifName) {
+ return new StringBuilder().append(dpnId).append(tableId).append(ifName).toString();
+ }
+
+
+ protected void makeTunnelIngressFlow(BigInteger dpnId, String ifName, int addOrRemoveFlow) {
+ long portNo = 0;
+ String flowName = ifName;
+ String flowRef = getTunnelInterfaceFlowRef(dpnId, VpnConstants.LPORT_INGRESS_TABLE, ifName);
+ List<MatchInfo> matches = new ArrayList<MatchInfo>();
+ List<InstructionInfo> mkInstructions = new ArrayList<InstructionInfo>();
+ if (NwConstants.ADD_FLOW == addOrRemoveFlow) {
+ portNo = interfaceManager.getPortForInterface(ifName);
+ matches.add(new MatchInfo(MatchFieldType.in_port, new BigInteger[] {
+ dpnId, BigInteger.valueOf(portNo) }));
+ mkInstructions.add(new InstructionInfo(InstructionType.goto_table, new long[] {VpnConstants.LFIB_TABLE}));
+ }
+
+ BigInteger COOKIE_VM_INGRESS_TABLE = new BigInteger("8000001", 16);
+ FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, VpnConstants.LPORT_INGRESS_TABLE, flowRef,
+ VpnConstants.DEFAULT_FLOW_PRIORITY, flowName, 0, 0, COOKIE_VM_INGRESS_TABLE, matches, mkInstructions);
+
+ if (NwConstants.ADD_FLOW == addOrRemoveFlow) {
+ mdsalManager.installFlow(flowEntity);
+ } else {
+ mdsalManager.removeFlow(flowEntity);
+ }
+ }
+
+ private class InterfaceListener extends AbstractDataChangeListener<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> {
+
+ public InterfaceListener() {
+ super(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.class);
+ }
+
+ @Override
+ protected void remove(InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> identifier,
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface del) {
+ LOG.trace("Operational Interface remove event - {}", del);
+ }
+
+ @Override
+ protected void update(InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> identifier,
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface original,
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface update) {
+ LOG.trace("Operation Interface update event - Old: {}, New: {}", original, update);
+ String interfaceName = update.getName();
+ Interface intf = getInterface(interfaceName);
+ if (intf != null && intf.getType().equals(L3tunnel.class)) {
+ BigInteger dpnId = interfaceManager.getDpnForInterface(interfaceName);
+ if(update.getOperStatus().equals(OperStatus.Up)) {
+ //Create ingress to LFIB
+ LOG.debug("Installing Ingress for tunnel interface {}", interfaceName);
+ makeTunnelIngressFlow(dpnId, interfaceName, NwConstants.ADD_FLOW);
+ } else if(update.getOperStatus().equals(OperStatus.Down)) {
+ LOG.debug("Removing Ingress flow for tunnel interface {}", interfaceName);
+ makeTunnelIngressFlow(dpnId, interfaceName, NwConstants.DEL_FLOW);
+ }
+ } else {
+ VpnInterface vpnInterface = getVpnInterface(interfaceName);
+ if(vpnInterface != null) {
+ if(update.getOperStatus().equals(OperStatus.Up)) {
+ LOG.debug("Installing VPN related rules for interface {}", interfaceName);
+ addInterface(VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getName()), vpnInterface);
+ } else if(update.getOperStatus().equals(OperStatus.Down)) {
+ LOG.debug("Removing VPN related rules for interface {}", interfaceName);
+ VpnInterfaceManager.this.remove(VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getName()), vpnInterface);
+ }
+ } else {
+ LOG.debug("No VPN Interface associated with interface {} to handle Update Operation", interfaceName);
+ }
+ }
+ }
+
+ @Override
+ protected void add(InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> identifier,
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface add) {
+ LOG.trace("Operational Interface add event - {}", add);
+ String interfaceName = add.getName();
+ Interface intf = getInterface(interfaceName);
+ if (intf != null && intf.getType().equals(L3tunnel.class)) {
+ BigInteger dpnId = interfaceManager.getDpnForInterface(interfaceName);
+ if(add.getOperStatus().equals(OperStatus.Up)) {
+ //Create ingress to LFIB
+ LOG.debug("Installing Ingress for tunnel interface {}", interfaceName);
+ makeTunnelIngressFlow(dpnId, interfaceName, NwConstants.ADD_FLOW);
+ }
+ } else {
+ VpnInterface vpnInterface = getVpnInterface(interfaceName);
+ if(vpnInterface != null) {
+ if(add.getOperStatus().equals(OperStatus.Up)) {
+ LOG.debug("Installing VPN related rules for interface {}", interfaceName);
+ addInterface(VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getName()), vpnInterface);
+ }
+ } else {
+ LOG.debug("No VPN Interface associated with interface {} to handle add Operation", interfaceName);
+ }
+ }
+ }
+ }