Bug 3738: GBP coexistence with SFC 95/33895/18
authorVladimir Lavor <vlavor@cisco.com>
Wed, 27 Jan 2016 10:42:29 +0000 (11:42 +0100)
committerMartin Sunal <msunal@cisco.com>
Thu, 11 Feb 2016 20:48:35 +0000 (20:48 +0000)
Change-Id: If5ed0e87485b88e02f525dab1072b75462d16a1f
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
Signed-off-by: Keith Burns (alagalah) <alagalah@gmail.com>
Signed-off-by: Martin Sunal <msunal@cisco.com>
46 files changed:
.gitignore
demos/gbp-devstack/Vagrantfile
demos/gbp-devstack/devstack-scripts/console.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/environment
demos/gbp-devstack/devstack-scripts/flowcount.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/hostdump.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/killrabbit.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/kssh.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/ndump.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/novaboot-compute.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/novaboot-control.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/novaboot.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/ovsshow.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/packetCount.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/pollflows.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/resetcontroller.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/resetmanager.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/restack.sh [changed mode: 0644->0755]
demos/gbp-devstack/devstack-scripts/sfc/control.local.conf
demos/gbp-devstack/devstack-scripts/unstack.sh [changed mode: 0644->0755]
demos/gbp-devstack/puppet/scripts/bootstrap.sh
demos/gbp-devstack/puppet/templates/compute.local.conf.erb
demos/gbp-devstack/puppet/templates/control.local.conf.erb
demos/gbpsfc-env/demo-asymmetric-coexistence/get-nsps.py [new file with mode: 0755]
demos/gbpsfc-env/demo-asymmetric-coexistence/infrastructure_config.py [new file with mode: 0755]
demos/gbpsfc-env/demo-asymmetric-coexistence/rest.py
demos/gbpsfc-env/demo-symmetric-coexistence/get-nsps.py [new file with mode: 0755]
demos/gbpsfc-env/demo-symmetric-coexistence/infrastructure_config.py [new file with mode: 0755]
demos/gbpsfc-env/demo-symmetric-coexistence/rest.py
demos/gbpsfc-env/demo.lock [deleted file]
demos/gbpsfc-env/dpdumpflows.py
demos/gbpsfc-env/dumpflows.sh
demos/gbpsfc-env/traceflow.sh
renderers/ofoverlay/pom.xml
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/PolicyManager.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/ChainActionFlows.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/FlowUtils.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/PortSecurity.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sfcutils/SfcIidFactory.java
renderers/ofoverlay/src/main/yang/ofoverlay.yang
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/PolicyManagerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/ChainActionFlowsTest.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/DestinationMapperTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/ExternalMapperTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/PolicyEnforcerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/PortSecurityTest.java

index 9167c72928a6460a796b8c0661c3b05a70a8f219..9564010ec151d3746fb6b5f25f2721ac110303fd 100644 (file)
@@ -1,3 +1,4 @@
+.DS_Store
 .idea/
 target/
 *.class
index e73d2b347cde0d0c542faea3540881b9c68fa4a0..9b95cf076f034a098682a26bc496a89a7d669e5c 100644 (file)
@@ -28,8 +28,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
     control.vm.network "private_network", ip: "#{control_ip}"
     control.vm.network "private_network", ip: "#{neutron_ex_ip}", virtualbox__intnet: "mylocalnet" 
     control.vm.provider :virtualbox do |vb|
-      vb.memory = 4096
-      vb.cpus = 2
+      vb.memory = 6192
+      vb.cpus = 
     end
     control.vm.provider "vmware_fusion" do |vf|
       vf.vmx["memsize"] = "4096"
old mode 100644 (file)
new mode 100755 (executable)
index 407eea01284c3c08d836e995fed68007d4613085..db5f3c2ed071e381041bfd3275e431b7092f2ff7 100644 (file)
@@ -1,2 +1,2 @@
-PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/vagrant/devstack-scripts:/vagrant/devstack-scripts/tutorial"
+PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/vagrant/devstack-scripts:/vagrant/devstack-scripts/tutorial:/vagrant/devstack-scripts/sfc"
 export ODL=192.168.50.1
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index cc77330..469e200
@@ -3,9 +3,9 @@
  sudo service rabbitmq-server restart
  sudo service mysql restart
 
-sudo ovs-vsctl set-manager tcp:192.168.50.1:6640
+sudo ovs-vsctl set-manager tcp:$ODL:6640
 sudo ovs-vsctl add-br br-int
-sudo ovs-vsctl set-controller tcp:192.168.50.1:6653
+sudo ovs-vsctl set-controller tcp:$ODL:6653
 
 echo "Removing all logs to save space..."
 sudo rm -rf /opt/stack/logs/*
index 466ec0d596d2455d96342d261547dda3fa55ab45..c6c6a5016ff61e939d02956d5912a31db8b71114 100644 (file)
@@ -149,7 +149,7 @@ quota_metadata_items=300
 quota_security_group_rules=200
 quota_security_groups=200
 quota_volumes=100
-#scheduler_default_filters = AllHostsFilter
+scheduler_default_filters = AllHostsFilter
 [quota]
 skip_isolated_core_check=true
 max_cores=128
old mode 100644 (file)
new mode 100755 (executable)
index d717ded9a09f582ec27439d8acc6f829ed7ed16e..087db9c52ff96b96070873fa4375fcddf41c9a3f 100644 (file)
@@ -30,6 +30,15 @@ apt-get update >/dev/null
 echo "Installing wget..."
 apt-get install -y wget >/dev/null
 
+# Install vim
+echo "Installing vim..."
+apt-get install -y vim >/dev/null
+
+# Setup paths
+echo "Copying paths and ODL environment variable from .../devstack-scripts/environment to /etc/environment"
+cp /vagrant/devstack-scripts/environment /etc/environment
+source /etc/environment
+
 # Install the PuppetLabs repo
 echo "Configuring PuppetLabs repo..."
 repo_deb_path=$(mktemp)
index 0c7c4e07f9c1e6025eaca8db6d0a94255e6a788e..98d750ee11237b9d079eea0d4342591df6d9022f 100644 (file)
@@ -1,6 +1,6 @@
 [[local|localrc]]
-#enable_plugin networking-odl https://github.com/stackforge/networking-odl
-enable_plugin networking-odl https://github.com/flavio-fernandes/networking-odl lithiumkilo
+enable_plugin networking-odl https://github.com/openstack/networking-odl stable/kilo
+
 
 LOGFILE=stack.sh.log
 LOG_COLOR=False
index 2e11d963606e775370ffec2d0db4273fa9ffc174..8e9280d537b491f62eb8a7f4688ccfbd707793e9 100644 (file)
@@ -1,7 +1,5 @@
 [[local|localrc]]
-#enable_plugin networking-odl https://github.com/stackforge/networking-odl
-#enable_plugin networking-odl /vagrant/x/networking-odl.git plugin
-enable_plugin networking-odl https://github.com/flavio-fernandes/networking-odl lithiumkilo
+enable_plugin networking-odl https://github.com/openstack/networking-odl stable/kilo
 
 LOGFILE=stack.sh.log
 SCREEN_LOGDIR=/opt/stack/data/log
diff --git a/demos/gbpsfc-env/demo-asymmetric-coexistence/get-nsps.py b/demos/gbpsfc-env/demo-asymmetric-coexistence/get-nsps.py
new file mode 100755 (executable)
index 0000000..17c034f
--- /dev/null
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+import socket
+import requests,json
+from requests.auth import HTTPBasicAuth
+import sys
+import os
+from subprocess import check_output
+from infrastructure_config import *
+
+
+DEFAULT_PORT='8181'
+USERNAME='admin'
+PASSWORD='admin'
+
+def get(host, port, uri):
+    url='http://'+host+":"+port+uri
+    #print url
+    r = requests.get(url, auth=HTTPBasicAuth(USERNAME, PASSWORD))
+    jsondata=json.loads(r.text)
+    return jsondata
+
+
+def get_rsps_uri():
+       return "/restconf/operational/rendered-service-path:rendered-service-paths"
+
+def doCmd(cmd):
+    listcmd=cmd.split()
+    print check_output(listcmd)
+
+if __name__ == "__main__":
+    # Launch main menu
+
+
+    # Some sensible defaults
+    controller=os.environ.get('ODL')
+    if controller == None:
+        sys.exit("No controller set.")
+    #else:
+       #print "Contacting controller at %s" % controller
+
+    resp=get(controller,DEFAULT_PORT,get_rsps_uri())
+    if len(resp['rendered-service-paths']) > 0:
+       paths=resp['rendered-service-paths']['rendered-service-path']
+
+       nsps=[]
+       for path in paths:
+           nsps.append(path['path-id'])
+       if len(nsps) > 0:
+           sw_index=int(socket.gethostname().split("gbpsfc",1)[1])-1
+           if sw_index in range(0,len(switches)+1):
+
+              controller=os.environ.get('ODL')
+              sw_type = switches[sw_index]['type']
+              sw_name = switches[sw_index]['name']
+              if sw_type == 'sf':
+                  print "******************************"
+                  print "Adding flows for %s as an SF." % sw_name
+                  print "******************************"
+                  doCmd('sudo /vagrant/demo-asymmetric-coexistence/sf-flows.sh %s' % min(nsps))
+
diff --git a/demos/gbpsfc-env/demo-asymmetric-coexistence/infrastructure_config.py b/demos/gbpsfc-env/demo-asymmetric-coexistence/infrastructure_config.py
new file mode 100755 (executable)
index 0000000..14b98d0
--- /dev/null
@@ -0,0 +1,51 @@
+# Config for switches, tunnelIP is the local IP address.
+switches = [
+            {'name': 'sw1',
+             'type': 'gbp',
+             'dpid': '1'},
+            {'name': 'sw2',
+             'type': 'gbp',
+             'dpid': '2'},
+            {'name': 'sw3',
+             'type': 'sf',
+             'dpid': '3'},
+            {'name': 'sw4',
+             'type': 'gbp',
+             'dpid': '4'},
+            {'name': 'sw5',
+             'type': 'sf',
+             'dpid': '5'},
+            {'name': 'sw6',
+             'type': 'none',
+             'dpid': '6'}
+           ]
+
+defaultContainerImage='alagalah/odlpoc_ovs230'
+
+#Note that tenant name and endpointGroup name come from policy_config.py
+
+hosts = [{'name': 'h35_2',
+          'mac': '00:00:00:00:35:02',
+          'ip': '10.0.35.2/24',
+          'switch': 'sw1'},
+         {'name': 'h35_3',
+          'ip': '10.0.35.3/24',
+          'mac': '00:00:00:00:35:03',
+          'switch': 'sw2'},
+         {'name': 'h35_4',
+          'ip': '10.0.35.4/24',
+          'mac': '00:00:00:00:35:04',
+          'switch': 'sw4'},
+         {'name': 'h36_2',
+          'ip': '10.0.36.2/24',
+          'mac': '00:00:00:00:36:02',
+          'switch': 'sw1'},
+         {'name': 'h36_3',
+          'ip': '10.0.36.3/24',
+          'mac': '00:00:00:00:36:03',
+          'switch': 'sw2'},
+         {'name': 'h36_4',
+          'ip': '10.0.36.4/24',
+          'mac': '00:00:00:00:36:04',
+          'switch': 'sw4'}
+          ]
\ No newline at end of file
index 530a9345a81d56571d08d71f10c8349bdf37e28e..722f6b589c9e07d69554510e95e36e1941ed1080 100755 (executable)
@@ -125,13 +125,13 @@ def get_service_function_forwarders_data():
                         "name": "firewall-72",
                         "sff-sf-data-plane-locator": {
                             "sf-dpl-name": "2",
-                            "sff-dpl-name": "sfc-tun2"
+                            "sff-dpl-name": "sw1-vxlangpe-0"
                         }
                     }
                 ],
                 "sff-data-plane-locator": [
                     {
-                        "name": "sfc-tun2",
+                        "name": "sw1-vxlangpe-0",
                         "data-plane-locator": {
                             "transport": "service-locator:vxlan-gpe",
                             "port": 6633,
@@ -162,13 +162,13 @@ def get_service_function_forwarders_data():
                         "name": "dpi-74",
                         "sff-sf-data-plane-locator": {
                             "sf-dpl-name": "3",
-                            "sff-dpl-name": "sfc-tun4"
+                            "sff-dpl-name": "sw2-vxlangpe-0"
                         }
                     }
                 ],
                 "sff-data-plane-locator": [
                     {
-                        "name": "sfc-tun4",
+                        "name": "sw2-vxlangpe-0",
                         "data-plane-locator": {
                             "transport": "service-locator:vxlan-gpe",
                             "port": 6633,
diff --git a/demos/gbpsfc-env/demo-symmetric-coexistence/get-nsps.py b/demos/gbpsfc-env/demo-symmetric-coexistence/get-nsps.py
new file mode 100755 (executable)
index 0000000..ce3ed05
--- /dev/null
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+import socket
+import requests,json
+from requests.auth import HTTPBasicAuth
+import sys
+import os
+from subprocess import check_output
+from infrastructure_config import *
+
+
+DEFAULT_PORT='8181'
+USERNAME='admin'
+PASSWORD='admin'
+
+def get(host, port, uri):
+    url='http://'+host+":"+port+uri
+    #print url
+    r = requests.get(url, auth=HTTPBasicAuth(USERNAME, PASSWORD))
+    jsondata=json.loads(r.text)
+    return jsondata
+
+
+def get_rsps_uri():
+       return "/restconf/operational/rendered-service-path:rendered-service-paths"
+
+def doCmd(cmd):
+    listcmd=cmd.split()
+    print check_output(listcmd)
+
+if __name__ == "__main__":
+    # Launch main menu
+
+
+    # Some sensible defaults
+    controller=os.environ.get('ODL')
+    if controller == None:
+        sys.exit("No controller set.")
+    #else:
+       #print "Contacting controller at %s" % controller
+
+    resp=get(controller,DEFAULT_PORT,get_rsps_uri())
+    if len(resp['rendered-service-paths']) > 0:
+       paths=resp['rendered-service-paths']['rendered-service-path']
+
+       nsps=[]
+       for path in paths:
+           nsps.append(path['path-id'])
+       if len(nsps) > 0:
+           sw_index=int(socket.gethostname().split("gbpsfc",1)[1])-1
+           if sw_index in range(0,len(switches)+1):
+
+              controller=os.environ.get('ODL')
+              sw_type = switches[sw_index]['type']
+              sw_name = switches[sw_index]['name']
+              if sw_type == 'sf':
+                  print "******************************"
+                  print "Adding flows for %s as an SF." % sw_name
+                  print "******************************"
+                  doCmd('sudo /vagrant/demo-symmetric-coexistence/sf-flows.sh %s' % min(nsps))
+
diff --git a/demos/gbpsfc-env/demo-symmetric-coexistence/infrastructure_config.py b/demos/gbpsfc-env/demo-symmetric-coexistence/infrastructure_config.py
new file mode 100755 (executable)
index 0000000..bdeb050
--- /dev/null
@@ -0,0 +1,51 @@
+# Config for switches, tunnelIP is the local IP address.
+switches = [
+            {'name': 'sw1',
+             'type': 'gbp',
+             'dpid': '1'},
+            {'name': 'sw2',
+             'type': 'gbp',
+             'dpid': '2'},
+            {'name': 'sw3',
+             'type': 'sf',
+             'dpid': '3'},
+            {'name': 'sw4',
+             'type': 'gbp',
+             'dpid': '4'},
+            {'name': 'sw5',
+             'type': 'sf',
+             'dpid': '5'},
+            {'name': 'sw6',
+             'type': 'none',
+             'dpid': '6'}
+           ]
+
+defaultContainerImage='alagalah/odlpoc_ovs230'
+
+#Note that tenant name and endpointGroup name come from policy_config.py
+
+hosts = [{'name': 'h35_2',
+          'mac': '00:00:00:00:35:02',
+          'ip': '10.0.35.2/24',
+          'switch': 'sw1'},
+         {'name': 'h35_3',
+          'ip': '10.0.35.3/24',
+          'mac': '00:00:00:00:35:03',
+          'switch': 'sw2'},
+         {'name': 'h35_4',
+          'ip': '10.0.35.4/24',
+          'mac': '00:00:00:00:35:04',
+          'switch': 'sw4'},
+         {'name': 'h36_2',
+          'ip': '10.0.36.2/24',
+          'mac': '00:00:00:00:36:02',
+          'switch': 'sw1'},
+         {'name': 'h36_3',
+          'ip': '10.0.36.3/24',
+          'mac': '00:00:00:00:36:03',
+          'switch': 'sw2'},
+         {'name': 'h36_4',
+          'ip': '10.0.36.4/24',
+          'mac': '00:00:00:00:36:04',
+          'switch': 'sw4'}
+          ]
index 6b99f6dfff3ce19ceeffbe6a5d0ad09022f6a790..c8caa10096e8e4bb7ddcd5dd2a5dfef623acf07a 100755 (executable)
@@ -125,13 +125,13 @@ def get_service_function_forwarders_data():
                         "name": "firewall-72",
                         "sff-sf-data-plane-locator": {
                             "sf-dpl-name": "2",
-                            "sff-dpl-name": "sfc-tun2"
+                            "sff-dpl-name": "sw1-vxlangpe-0"
                         }
                     }
                 ],
                 "sff-data-plane-locator": [
                     {
-                        "name": "sfc-tun2",
+                        "name": "sw1-vxlangpe-0",
                         "data-plane-locator": {
                             "transport": "service-locator:vxlan-gpe",
                             "port": 6633,
@@ -162,13 +162,13 @@ def get_service_function_forwarders_data():
                         "name": "dpi-74",
                         "sff-sf-data-plane-locator": {
                             "sf-dpl-name": "3",
-                            "sff-dpl-name": "sfc-tun4"
+                            "sff-dpl-name": "sw2-vxlangpe-0"
                         }
                     }
                 ],
                 "sff-data-plane-locator": [
                     {
-                        "name": "sfc-tun4",
+                        "name": "sw2-vxlangpe-0",
                         "data-plane-locator": {
                             "transport": "service-locator:vxlan-gpe",
                             "port": 6633,
@@ -418,7 +418,7 @@ def get_tenant_data():
                           ],
                           "action-ref": [
                             {
-                              "name": "allow1",
+                              "name": "chain1",
                               "order": 0
                             }
                           ]
diff --git a/demos/gbpsfc-env/demo.lock b/demos/gbpsfc-env/demo.lock
deleted file mode 100644 (file)
index 0f5b955..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Uninitialised. Please do a ./cleandemo.sh
index a92034401fbfed9372834ca4e5a87bc81a1a2f95..aa0f415a06747a6c4dea849a912622741d2cfb3d 100755 (executable)
@@ -10,8 +10,11 @@ def call_dpctl():
 
 if __name__ == "__main__" :
        flows=call_dpctl().split("recirc_id")
+       print
+       print "Flows from dpctl:"
+       print 
        for flow in flows:
-               print flow
+               if flow != "": print "recirc_id"+flow
 
 
 
index ba8f27112677f00b9d1a9f545062cda8f00d091e..942aa64eceb7755db18eb049eaca5484b061781b 100755 (executable)
@@ -10,7 +10,7 @@ clear
 ovs-ofctl dump-groups $sw -OOpenFlow13
 if [ "$TABLE" ]
 then
-        ovs-ofctl dump-flows $sw -OOpenFlow13 table=$TABLE
+        ovs-ofctl dump-flows $sw -OOpenFlow13 table=$TABLE --rsort=priority
 else
         ovs-ofctl dump-flows $sw -OOpenFlow13
 fi
index ca2426e59268bff10614f578c8a81512af53535a..2c50497f847060da956bfde52a053918c3d23601 100755 (executable)
@@ -1 +1,5 @@
-ovs-appctl ofproto/trace $1
+STR=$1
+
+TRACE=${STR%", packets"*}
+
+ovs-appctl ofproto/trace $TRACE
index 45c553484eddbcffbde66161b6580320b79bc905..0ddabf385adc243cf71fd25a78ef466118517f95 100755 (executable)
       <type>test-jar</type>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.powermock</groupId>
+      <artifactId>powermock-module-junit4</artifactId>
+      <version>1.5.2</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.powermock</groupId>
+      <artifactId>powermock-api-mockito</artifactId>
+      <version>1.5.2</version>
+      <scope>test</scope>
+    </dependency>
 
   </dependencies>
 
index ec2e9b589a0eb14004bb3d82eb9024924ba1a89f..02fba5e9d6cbc91a8a65a47063d17e2fe9443283 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014 Cisco Systems, Inc. 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,
@@ -44,9 +44,12 @@ import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.PortSecurity;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.SourceMapper;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchListener;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcIidFactory;
 import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
 import org.opendaylight.groupbasedpolicy.util.IidFactory;
 import org.opendaylight.groupbasedpolicy.util.SingletonTask;
+import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.sfc.of.renderer.rev151123.SfcOfRendererConfig;
+import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.sfc.of.renderer.rev151123.SfcOfRendererConfigBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayConfig.LearningMode;
@@ -74,20 +77,22 @@ import com.google.common.util.concurrent.ListenableFuture;
  * registry
  */
 public class PolicyManager
-     implements SwitchListener, EndpointListener, DataTreeChangeListener<ResolvedPolicy>, Closeable {
-    private static final Logger LOG =
-            LoggerFactory.getLogger(PolicyManager.class);
+        implements SwitchListener, EndpointListener, DataTreeChangeListener<ResolvedPolicy>, Closeable {
+
+    private static final Logger LOG = LoggerFactory.getLogger(PolicyManager.class);
 
     private Map<InstanceIdentifier<Table>, TableBuilder> previousGbpFlows  = new HashMap<>();
 
     private short tableOffset;
     private static final short TABLEID_PORTSECURITY = 0;
-    private static final short TABLEID_INGRESS_NAT =  1;
+    private static final short TABLEID_INGRESS_NAT = 1;
     private static final short TABLEID_SOURCE_MAPPER = 2;
     private static final short TABLEID_DESTINATION_MAPPER = 3;
     private static final short TABLEID_POLICY_ENFORCER = 4;
     private static final short TABLEID_EGRESS_NAT = 5;
     private static final short TABLEID_EXTERNAL_MAPPER = 6;
+    private static final short TABLEID_SFC_INGRESS = 7;
+    private static final short TABLEID_SFC_EGRESS = 0;
 
     private final SwitchManager switchManager;
     private final EndpointManager endpointManager;
@@ -104,11 +109,8 @@ public class PolicyManager
      */
     private final static int FLOW_UPDATE_DELAY = 250;
 
-    public PolicyManager(DataBroker dataBroker,
-                         SwitchManager switchManager,
-                         EndpointManager endpointManager,
-                         ScheduledExecutorService executor,
-                         short tableOffset) {
+    public PolicyManager(DataBroker dataBroker, SwitchManager switchManager, EndpointManager endpointManager,
+            ScheduledExecutorService executor, short tableOffset) {
         super();
         this.switchManager = switchManager;
         this.executor = executor;
@@ -137,26 +139,35 @@ public class PolicyManager
         this.endpointManager = endpointManager;
         endpointManager.registerListener(this);
 
+        if (!setSfcTableOffset(TABLEID_SFC_INGRESS, TABLEID_SFC_EGRESS)) {
+            LOG.error("Could not set SFC Ingress Table offset.");
+        }
         flowUpdateTask = new SingletonTask(executor, new FlowUpdateTask());
         scheduleUpdate();
 
         LOG.debug("Initialized OFOverlay policy manager");
     }
 
+    private boolean setSfcTableOffset(short tableidSfcIngress, short tableidSfcEgress) {
+        SfcOfRendererConfig sfcOfRendererConfig = new SfcOfRendererConfigBuilder()
+            .setSfcOfTableOffset(tableidSfcIngress).setSfcOfAppEgressTableOffset(tableidSfcEgress).build();
+        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
+        wTx.put(LogicalDatastoreType.CONFIGURATION, SfcIidFactory.sfcOfRendererConfigIid(), sfcOfRendererConfig);
+        return DataStoreHelper.submitToDs(wTx);
+    }
+
     private List<? extends OfTable> createFlowPipeline(OfContext ofCtx) {
         // TODO - PORTSECURITY is kept in table 0.
         // According to openflow spec,processing on vSwitch always starts from table 0.
         // Packets will be droped if table 0 is empty.
         // Alternative workaround - table-miss flow entries in table 0.
-        return ImmutableList.of(new PortSecurity(ofCtx, (short) 0),
-                                        new GroupTable(ofCtx),
-                                        new IngressNatMapper(ofCtx, getTABLEID_INGRESS_NAT()),
-                                        new SourceMapper(ofCtx, getTABLEID_SOURCE_MAPPER()),
-                                        new DestinationMapper(ofCtx, getTABLEID_DESTINATION_MAPPER()),
-                                        new PolicyEnforcer(ofCtx, getTABLEID_POLICY_ENFORCER()),
-                                        new EgressNatMapper(ofCtx, getTABLEID_EGRESS_NAT()),
-                                        new ExternalMapper(ofCtx, getTABLEID_EXTERNAL_MAPPER())
-                                        );
+        return ImmutableList.of(new PortSecurity(ofCtx, (short) 0), new GroupTable(ofCtx),
+                new IngressNatMapper(ofCtx, getTABLEID_INGRESS_NAT()),
+                new SourceMapper(ofCtx, getTABLEID_SOURCE_MAPPER()),
+                new DestinationMapper(ofCtx, getTABLEID_DESTINATION_MAPPER()),
+                new PolicyEnforcer(ofCtx, getTABLEID_POLICY_ENFORCER()),
+                new EgressNatMapper(ofCtx, getTABLEID_EGRESS_NAT()),
+                new ExternalMapper(ofCtx, getTABLEID_EXTERNAL_MAPPER()));
     }
 
     /**
@@ -186,7 +197,7 @@ public class PolicyManager
     }
 
     /**
-     * @param  tableIDs - IDs of tables to delete
+     * @param tableIDs - IDs of tables to delete
      * @return ListenableFuture<Void> - which will be filled when clearing is done
      */
     private ListenableFuture<Void> removeUnusedTables(final List<Short> tableIDs) {
@@ -220,16 +231,19 @@ public class PolicyManager
         return tableIds;
     }
 
-    private ListenableFuture<Void> deleteTableIfExists(final ReadWriteTransaction rwTx, final InstanceIdentifier<Table> tablePath){
-    return Futures.transform(rwTx.read(LogicalDatastoreType.CONFIGURATION, tablePath), new Function<Optional<Table>, Void>() {
-
-        @Override
-        public Void apply(Optional<Table> optTable) {
-            if(optTable.isPresent()){
-                rwTx.delete(LogicalDatastoreType.CONFIGURATION, tablePath);
-            }
-            return null;
-        }});
+    private ListenableFuture<Void> deleteTableIfExists(final ReadWriteTransaction rwTx,
+            final InstanceIdentifier<Table> tablePath) {
+        return Futures.transform(rwTx.read(LogicalDatastoreType.CONFIGURATION, tablePath),
+                new Function<Optional<Table>, Void>() {
+
+                    @Override
+                    public Void apply(Optional<Table> optTable) {
+                        if (optTable.isPresent()) {
+                            rwTx.delete(LogicalDatastoreType.CONFIGURATION, tablePath);
+                        }
+                        return null;
+                    }
+                });
     }
 
     // **************
@@ -237,42 +251,43 @@ public class PolicyManager
     // **************
 
     public short getTABLEID_PORTSECURITY() {
-        return (short)(tableOffset+TABLEID_PORTSECURITY);
+        return (short) (tableOffset + TABLEID_PORTSECURITY);
     }
 
-
     public short getTABLEID_INGRESS_NAT() {
-        return (short)(tableOffset+TABLEID_INGRESS_NAT);
+        return (short) (tableOffset + TABLEID_INGRESS_NAT);
     }
 
-
     public short getTABLEID_SOURCE_MAPPER() {
-        return (short)(tableOffset+TABLEID_SOURCE_MAPPER);
+        return (short) (tableOffset + TABLEID_SOURCE_MAPPER);
     }
 
-
     public short getTABLEID_DESTINATION_MAPPER() {
-        return (short)(tableOffset+TABLEID_DESTINATION_MAPPER);
+        return (short) (tableOffset + TABLEID_DESTINATION_MAPPER);
     }
 
-
     public short getTABLEID_POLICY_ENFORCER() {
-        return (short)(tableOffset+TABLEID_POLICY_ENFORCER);
+        return (short) (tableOffset + TABLEID_POLICY_ENFORCER);
     }
 
-
     public short getTABLEID_EGRESS_NAT() {
-        return (short)(tableOffset+TABLEID_EGRESS_NAT);
+        return (short) (tableOffset + TABLEID_EGRESS_NAT);
     }
 
-
     public short getTABLEID_EXTERNAL_MAPPER() {
-        return (short)(tableOffset+TABLEID_EXTERNAL_MAPPER);
+        return (short) (tableOffset + TABLEID_EXTERNAL_MAPPER);
     }
 
+    public short getTABLEID_SFC_EGRESS() {
+        return TABLEID_SFC_EGRESS;
+    }
+
+    public short getTABLEID_SFC_INGRESS() {
+        return TABLEID_SFC_INGRESS;
+    }
 
     public TableId verifyMaxTableId(short tableOffset) {
-        return new TableId((short)(tableOffset+TABLEID_EXTERNAL_MAPPER));
+        return new TableId((short) (tableOffset + TABLEID_EXTERNAL_MAPPER));
     }
 
     @Override
@@ -301,7 +316,7 @@ public class PolicyManager
     }
 
     @Override
-    public void nodeEndpointUpdated(NodeId nodeId, EpKey epKey){
+    public void nodeEndpointUpdated(NodeId nodeId, EpKey epKey) {
         scheduleUpdate();
     }
 
@@ -335,6 +350,7 @@ public class PolicyManager
 
     /**
      * Set the learning mode to the specified value
+     *
      * @param learningMode the learning mode to set
      */
     public void setLearningMode(LearningMode learningMode) {
@@ -356,6 +372,7 @@ public class PolicyManager
      * Update the flows on a particular switch
      */
     private class SwitchFlowUpdateTask implements Callable<Void> {
+
         private final OfWriter ofWriter;
 
         public SwitchFlowUpdateTask(OfWriter ofWriter) {
@@ -373,8 +390,7 @@ public class PolicyManager
                     try {
                         table.sync(node, ofWriter);
                     } catch (Exception e) {
-                        LOG.error("Failed to write Openflow table {}",
-                                table.getClass().getSimpleName(), e);
+                        LOG.error("Failed to write Openflow table {}", table.getClass().getSimpleName(), e);
                     }
                 }
             }
@@ -383,16 +399,16 @@ public class PolicyManager
     }
 
     /**
-     * Update all flows on all switches as needed.  Note that this will block
+     * Update all flows on all switches as needed. Note that this will block
      * one of the threads on the executor.
      */
     private class FlowUpdateTask implements Runnable {
+
         @Override
         public void run() {
             LOG.debug("Beginning flow update task");
 
-            CompletionService<Void> ecs
-                = new ExecutorCompletionService<>(executor);
+            CompletionService<Void> ecs = new ExecutorCompletionService<>(executor);
 
             OfWriter ofWriter = new OfWriter();
 
index 965490cf46ad1e92ffeb4f2e68f5bdb96b449eef..5e5970196069fd4226125a27ee251d50a9a58846 100755 (executable)
@@ -26,13 +26,18 @@ import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtil
 
 import java.math.BigInteger;
 
+import org.apache.commons.lang3.StringUtils;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.RegMatch;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.PolicyEnforcer.NetworkElements;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.ChainAction;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader;
+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.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
@@ -51,6 +56,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.annotations.VisibleForTesting;
+
 public class ChainActionFlows {
 
     private static final Logger LOG = LoggerFactory.getLogger(ChainAction.class);
@@ -68,34 +75,29 @@ public class ChainActionFlows {
 
         NodeConnectorId localNodeTunPort = ctx.getSwitchManager().getTunnelPort(localNodeId, TunnelTypeVxlanGpe.class);
         NodeConnectorId destNodeTunPort = ctx.getSwitchManager().getTunnelPort(destNodeId, TunnelTypeVxlanGpe.class);
+        Ipv4Address tunDestAddress = ctx.getSwitchManager()
+            .getTunnelIP(netElements.getDstNodeId(), TunnelTypeVxlanGpe.class)
+            .getIpv4Address();
         if (localNodeTunPort == null || destNodeTunPort == null) {
             LOG.error("createChainTunnelFlows: No valid VXLAN GPE tunnel for Node {} or Node {}", localNodeId,
                     destNodeId);
             return;
         }
-        ofWriter.writeFlow(localNodeId, ctx.getPolicyManager().getTABLEID_PORTSECURITY(),
-                allowFromChainPort(localNodeTunPort, ctx.getPolicyManager().getTABLEID_PORTSECURITY(), ctx));
+        ofWriter.writeFlow(localNodeId, ctx.getPolicyManager().getTABLEID_PORTSECURITY(), allowFromChainPort(
+                sfcNshHeader, localNodeTunPort, ctx.getPolicyManager().getTABLEID_PORTSECURITY(), ctx));
 
         ofWriter.writeFlow(localNodeId, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER(),
                 allowFromChainTunnel(localNodeTunPort, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER()));
 
-        ofWriter.writeFlow(
-                localNodeId,
-                ctx.getPolicyManager().getTABLEID_EXTERNAL_MAPPER(),
-                createExternalFlow(sfcNshHeader, localNodeTunPort, netElements, ctx.getPolicyManager()
-                    .getTABLEID_EXTERNAL_MAPPER(), ctx));
-
-        ofWriter.writeFlow(
-                destNodeId,
-                ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER(),
-                createChainTunnelFlow(sfcNshHeader, destNodeTunPort, epOrdinals, ctx.getPolicyManager()
-                    .getTABLEID_SOURCE_MAPPER(), ctx));
-
-        ofWriter.writeFlow(
-                destNodeId,
-                ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER(),
-                createChainBroadcastFlow(sfcNshHeader, destNodeTunPort, epOrdinals, ctx.getPolicyManager()
-                    .getTABLEID_SOURCE_MAPPER(), ctx));
+        ofWriter.writeFlow(localNodeId, ctx.getPolicyManager().getTABLEID_EXTERNAL_MAPPER(),
+                createExternalFlow(sfcNshHeader, localNodeTunPort, netElements,
+                        ctx.getPolicyManager(), ctx.getSwitchManager(), tunDestAddress));
+
+        ofWriter.writeFlow(destNodeId, ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER(), createChainTunnelFlow(
+                sfcNshHeader, destNodeTunPort, epOrdinals, ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER(), ctx));
+
+        ofWriter.writeFlow(destNodeId, ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER(), createChainBroadcastFlow(
+                sfcNshHeader, destNodeTunPort, epOrdinals, ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER(), ctx));
     }
 
     private static Flow createChainBroadcastFlow(SfcNshHeader sfcNshHeader, NodeConnectorId tunPort,
@@ -109,34 +111,49 @@ public class ChainActionFlows {
         addNxNspMatch(mb, sfcNshHeader.getNshNspFromChain());
         addNxTunIdMatch(mb, fdId);
 
-        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action fdReg = nxLoadRegAction(
-                NxmNxReg5.class, BigInteger.valueOf(fdId));
+        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action fdReg =
+                nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(fdId));
 
         Match match = mb.build();
         FlowId flowId = FlowIdUtils.newFlowId(tableId, "chainbroadcast", match);
 
         FlowBuilder flowb = base(tableId).setId(flowId)
-            .setPriority(Integer.valueOf(150))
+            .setPriority(150)
             .setMatch(match)
-            .setInstructions(
-                    instructions(applyActionIns(fdReg), gotoTableIns(ctx.getPolicyManager()
-                        .getTABLEID_DESTINATION_MAPPER())));
+            .setInstructions(instructions(applyActionIns(fdReg),
+                    gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));
         return flowb.build();
     }
 
-    private static Flow createExternalFlow(SfcNshHeader sfcNshHeader, NodeConnectorId tunPort,
-            NetworkElements netElements, short tableId, OfContext ctx) {
+    @VisibleForTesting
+    static Flow createExternalFlow(SfcNshHeader sfcNshHeader, NodeConnectorId tunPort, NetworkElements netElements,
+                                   PolicyManager policyManager, SwitchManager switchManager, Ipv4Address ipTunDest) {
+
+        short tableId = policyManager.getTABLEID_EXTERNAL_MAPPER();
+        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadC1;
+        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action outputAction;
 
         Integer priority = 1000;
-        int matchTunnelId=sfcNshHeader.getNshMetaC2().intValue();
-        Long l3c=Long.valueOf(netElements.getSrcEpOrdinals().getL3Id());
+        int matchTunnelId = sfcNshHeader.getNshMetaC2().intValue();
+        Long l3c = (long) netElements.getSrcEpOrdinals().getL3Id();
+        loadC1 = nxLoadNshc1RegAction(sfcNshHeader.getNshMetaC1());
+
+        // Test for if SFF is on same node
+        IpAddress ipAddress = switchManager.getTunnelIP(netElements.getLocalNodeId(), TunnelTypeVxlanGpe.class);
+
+        if (ipAddress != null && ipAddress.getIpv4Address().equals(sfcNshHeader.getNshTunIpDst())) {
+            Integer newPort = returnOfPortFromNodeConnector(tunPort);
+            outputAction = FlowUtils.createActionResubmit(newPort, policyManager.getTABLEID_SFC_EGRESS());
+        } else {
+            outputAction = outputAction(tunPort);
+        }
 
-        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadC1 = nxLoadNshc1RegAction(sfcNshHeader.getNshMetaC1());
-        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadC2 = nxLoadNshc2RegAction(sfcNshHeader.getNshMetaC2());
-        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadChainTunVnid = nxLoadTunIdAction(
-                BigInteger.valueOf(sfcNshHeader.getNshMetaC2()), false);
-        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadChainTunDest = nxLoadTunIPv4Action(
-                sfcNshHeader.getNshTunIpDst().getValue(), false);
+        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadC2 =
+                nxLoadNshc2RegAction(sfcNshHeader.getNshMetaC2());
+        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadChainTunVnid =
+                nxLoadTunIdAction(BigInteger.valueOf(sfcNshHeader.getNshMetaC2()), false);
+        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadChainTunDest =
+                nxLoadTunIPv4Action(sfcNshHeader.getNshTunIpDst().getValue(), false);
 
         MatchBuilder mb = new MatchBuilder();
         addNxRegMatch(mb, RegMatch.of(NxmNxReg6.class, l3c));
@@ -144,20 +161,15 @@ public class ChainActionFlows {
         addNxNspMatch(mb, sfcNshHeader.getNshNspToChain());
         addNxNsiMatch(mb, sfcNshHeader.getNshNsiToChain());
         if (!netElements.getDstNodeId().equals(netElements.getSrcNodeId())) {
-            addNxTunIpv4DstMatch(mb, ctx.getSwitchManager()
-                .getTunnelIP(netElements.getDstNodeId(), TunnelTypeVxlanGpe.class)
-                .getIpv4Address());
+            addNxTunIpv4DstMatch(mb, ipTunDest);
             priority = 1500;
         }
 
         Match match = mb.build();
         FlowId flowId = FlowIdUtils.newFlowId(tableId, "chainexternal", match);
-        FlowBuilder flowb = base(tableId).setId(flowId)
-            .setPriority(Integer.valueOf(priority))
-            .setMatch(match)
-            .setInstructions(
-                    instructions(applyActionIns(loadC1, loadC2, loadChainTunDest, loadChainTunVnid,
-                            outputAction(tunPort))));
+        FlowBuilder flowb =
+                base(tableId).setId(flowId).setPriority(priority).setMatch(match).setInstructions(
+                        instructions(applyActionIns(loadC1, loadC2, loadChainTunDest, loadChainTunVnid, outputAction)));
         return flowb.build();
     }
 
@@ -175,54 +187,64 @@ public class ChainActionFlows {
         addNxNspMatch(mb, sfcNshHeader.getNshNspFromChain());
         addNxNsiMatch(mb, sfcNshHeader.getNshNsiFromChain());
 
-        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action segReg = nxLoadRegAction(
-                NxmNxReg0.class, BigInteger.valueOf(egId));
-        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action scgReg = nxLoadRegAction(
-                NxmNxReg1.class, BigInteger.valueOf(0xffffff));
-        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action bdReg = nxLoadRegAction(
-                NxmNxReg4.class, BigInteger.valueOf(bdId));
-        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action fdReg = nxLoadRegAction(
-                NxmNxReg5.class, BigInteger.valueOf(fdId));
-        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action vrfReg = nxLoadRegAction(
-                NxmNxReg6.class, BigInteger.valueOf(l3Id));
+        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action segReg =
+                nxLoadRegAction(NxmNxReg0.class, BigInteger.valueOf(egId));
+        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action scgReg =
+                nxLoadRegAction(NxmNxReg1.class, BigInteger.valueOf(0xffffff));
+        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action bdReg =
+                nxLoadRegAction(NxmNxReg4.class, BigInteger.valueOf(bdId));
+        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action fdReg =
+                nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(fdId));
+        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action vrfReg =
+                nxLoadRegAction(NxmNxReg6.class, BigInteger.valueOf(l3Id));
 
         Match match = mb.build();
         FlowId flowId = FlowIdUtils.newFlowId(tableId, "chaintunnel", match);
-        FlowBuilder flowb = base(tableId).setId(flowId)
-            .setPriority(Integer.valueOf(150))
-            .setMatch(match)
-            .setInstructions(
-                    instructions(applyActionIns(segReg, scgReg, bdReg, fdReg, vrfReg),
-                            gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));
+        FlowBuilder flowb =
+                base(tableId).setId(flowId).setPriority(150).setMatch(match).setInstructions(
+                        instructions(applyActionIns(segReg, scgReg, bdReg, fdReg, vrfReg),
+                                gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));
         return flowb.build();
     }
 
-    private static Flow allowFromChainPort(NodeConnectorId port, short tableId, OfContext ctx) {
+    private static Flow allowFromChainPort(SfcNshHeader sfcNshHeader, NodeConnectorId port, short tableId,
+            OfContext ctx) {
+
+        // Matching on last NSP/NSI that SFF leaves on but with C1=0
+        MatchBuilder mb = new MatchBuilder();
+        FlowUtils.addNxNshc1RegMatch(mb, 0L);
+        FlowUtils.addNxNsiMatch(mb, sfcNshHeader.getNshNsiFromChain());
+        FlowUtils.addNxNspMatch(mb, sfcNshHeader.getNshNspFromChain());
+        Match match = mb.setInPort(port).build();
 
-        Match match = new MatchBuilder().setInPort(port).build();
         FlowId flowId = FlowIdUtils.newFlowId(tableId, "chainport", match);
-        FlowBuilder flowb = base(tableId).setId(flowId)
-            .setPriority(Integer.valueOf(200))
-            .setMatch(match)
-            .setInstructions(FlowUtils.gotoTableInstructions(ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER()));
+        FlowBuilder flowb =
+                base(tableId).setId(flowId).setPriority(1200).setMatch(match).setInstructions(
+                        FlowUtils.gotoTableInstructions(ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER()));
         return flowb.build();
     }
 
     private static Flow allowFromChainTunnel(NodeConnectorId tunPort, short tableId) {
 
         MatchBuilder mb = new MatchBuilder().setInPort(tunPort);
-        addNxRegMatch(mb, RegMatch.of(NxmNxReg1.class, Long.valueOf(0xffffff)));
+        addNxRegMatch(mb, RegMatch.of(NxmNxReg1.class, 0xffffffL));
         Match match = mb.build();
         FlowId flowId = FlowIdUtils.newFlowId(tableId, "chainport", match);
 
-        FlowBuilder flow = base(tableId).setId(flowId)
-            .setMatch(match)
-            .setPriority(65000)
-            .setInstructions(instructions(applyActionIns(nxOutputRegAction(NxmNxReg7.class))));
+        FlowBuilder flow = base(tableId).setId(flowId).setMatch(match).setPriority(65000).setInstructions(
+                instructions(applyActionIns(nxOutputRegAction(NxmNxReg7.class))));
         return flow.build();
 
     }
 
+    @VisibleForTesting
+    static Integer returnOfPortFromNodeConnector(NodeConnectorId nodeConnectorId) {
+        String[] elements = StringUtils.split(nodeConnectorId.getValue(), ":");
+        if (elements.length != 3)
+            return null;
+        return new Integer(elements[2]);
+    }
+
     /**
      * Get a base flow builder with some common features already set
      */
index 3279cebdc27b9777cda9c45276af61efdd79418f..1aa784659fe26461151c11322328fb7d476724f9 100755 (executable)
@@ -12,6 +12,9 @@ import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
+import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action.ActionUtil;
+import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action.ResubmitConvertor;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
@@ -83,6 +86,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionResubmitBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.resubmit.grouping.NxActionResubmitBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
@@ -187,19 +192,19 @@ public final class FlowUtils {
     /**
      * ARP ethertype
      */
-    public static final Long ARP = Long.valueOf(0x0806);
+    public static final Long ARP = 0x0806L;
     /**
      * IPv4 ethertype
      */
-    public static final Long IPv4 = Long.valueOf(0x0800);
+    public static final Long IPv4 = 0x0800L;
     /**
      * IPv6 ethertype
      */
-    public static final Long IPv6 = Long.valueOf(0x86DD);
+    public static final Long IPv6 = 0x86DDL;
     /**
      * VLAN ethertype
      */
-    public static final Integer VLAN = Integer.valueOf(0x8100);
+    public static final Integer VLAN = 0x8100;
 
     /**
      * Creates an Instance Identifier (path) for node with specified id
@@ -207,7 +212,7 @@ public final class FlowUtils {
      * @param nodeId the ID of the node
      * @return the {@link InstanceIdentifier}
      */
-    public static final InstanceIdentifier<Node> createNodePath(final NodeId nodeId) {
+    public static InstanceIdentifier<Node> createNodePath(final NodeId nodeId) {
         return InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(nodeId)).build();
     }
 
@@ -218,7 +223,7 @@ public final class FlowUtils {
      * @param tableId the ID of the table
      * @return the {@link InstanceIdentifier}
      */
-    public static final InstanceIdentifier<Table> createTablePath(final NodeId nodeId, final short tableId) {
+    public static InstanceIdentifier<Table> createTablePath(final NodeId nodeId, final short tableId) {
         return createNodePath(nodeId).builder()
             .augmentation(FlowCapableNode.class)
             .child(Table.class, new TableKey(tableId))
@@ -232,7 +237,7 @@ public final class FlowUtils {
      * @param groupId the ID of the group table
      * @return the {@link InstanceIdentifier}
      */
-    public static final InstanceIdentifier<Group> createGroupPath(final NodeId nodeId, final GroupId groupId) {
+    public static InstanceIdentifier<Group> createGroupPath(final NodeId nodeId, final GroupId groupId) {
         return createNodePath(nodeId).builder()
             .augmentation(FlowCapableNode.class)
             .child(Group.class, new GroupKey(groupId))
@@ -251,8 +256,8 @@ public final class FlowUtils {
      * @param bucketId the ID of the bucket in the group table
      * @return the {@link InstanceIdentifier}
      */
-    public static final InstanceIdentifier<Bucket> createBucketPath(final NodeId nodeId, final GroupId groupId,
-            final BucketId bucketId) {
+    public static InstanceIdentifier<Bucket> createBucketPath(final NodeId nodeId, final GroupId groupId,
+                                                              final BucketId bucketId) {
         return createNodePath(nodeId).builder()
             .augmentation(FlowCapableNode.class)
             .child(Group.class, new GroupKey(groupId))
@@ -269,7 +274,8 @@ public final class FlowUtils {
      * @param flowKey the flow key
      * @return the {@link InstanceIdentifier}
      */
-    public static InstanceIdentifier<Flow> createFlowPath(final InstanceIdentifier<Table> table, final FlowKey flowKey) {
+    public static InstanceIdentifier<Flow> createFlowPath(final InstanceIdentifier<Table> table,
+            final FlowKey flowKey) {
         return table.child(Flow.class, flowKey);
     }
 
@@ -287,7 +293,7 @@ public final class FlowUtils {
 
     public static Instructions gotoTableInstructions(short tableId) {
         return new InstructionsBuilder().setInstruction(
-                ImmutableList.of(new InstructionBuilder().setOrder(Integer.valueOf(0))
+                ImmutableList.of(new InstructionBuilder().setOrder(0)
                     .setInstruction(gotoTableIns(tableId))
                     .build())).build();
     }
@@ -298,46 +304,49 @@ public final class FlowUtils {
 
     public static ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList(
             Action... actions) {
-        ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> alist = new ArrayList<>();
+        ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> alist =
+                new ArrayList<>();
         int count = 0;
         for (Action action : actions) {
-            alist.add(new ActionBuilder().setOrder(Integer.valueOf(count++)).setAction(action).build());
+            alist.add(new ActionBuilder().setOrder(count++).setAction(action).build());
         }
         return alist;
     }
 
     public static ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList(
             List<ActionBuilder> actions) {
-        ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> alist = new ArrayList<>();
+        ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> alist =
+                new ArrayList<>();
         int count = 0;
         for (ActionBuilder action : actions) {
-            alist.add(action.setOrder(Integer.valueOf(count++)).build());
+            alist.add(action.setOrder(count++).build());
         }
         return alist;
     }
 
     public static Instruction applyActionIns(Action... actions) {
-        return new ApplyActionsCaseBuilder().setApplyActions(
-                new ApplyActionsBuilder().setAction(actionList(actions)).build()).build();
+        return new ApplyActionsCaseBuilder()
+            .setApplyActions(new ApplyActionsBuilder().setAction(actionList(actions)).build()).build();
     }
 
     public static Instruction applyActionIns(List<ActionBuilder> actions) {
-        return new ApplyActionsCaseBuilder().setApplyActions(
-                new ApplyActionsBuilder().setAction(actionList(actions)).build()).build();
+        return new ApplyActionsCaseBuilder()
+            .setApplyActions(new ApplyActionsBuilder().setAction(actionList(actions)).build()).build();
     }
 
     public static Instruction writeActionIns(List<ActionBuilder> actions) {
-        return new WriteActionsCaseBuilder().setWriteActions(
-                new WriteActionsBuilder().setAction(actionList(actions)).build()).build();
+        return new WriteActionsCaseBuilder()
+            .setWriteActions(new WriteActionsBuilder().setAction(actionList(actions)).build()).build();
     }
 
     public static Instruction writeActionIns(Action... actions) {
-        return new WriteActionsCaseBuilder().setWriteActions(
-                new WriteActionsBuilder().setAction(actionList(actions)).build()).build();
+        return new WriteActionsCaseBuilder()
+            .setWriteActions(new WriteActionsBuilder().setAction(actionList(actions)).build()).build();
     }
 
     public static Instructions instructions(Instruction... instructions) {
-        ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction> ins = new ArrayList<>();
+        ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction> ins =
+                new ArrayList<>();
         int order = 0;
         for (Instruction i : instructions) {
             ins.add(new InstructionBuilder().setOrder(order++).setInstruction(i).build());
@@ -353,9 +362,26 @@ public final class FlowUtils {
         return new DropActionCaseBuilder().setDropAction(new DropActionBuilder().build()).build();
     }
 
+    public static Action createActionResubmit(Integer port, final short toTable) {
+        NxActionResubmitBuilder resubmit = new NxActionResubmitBuilder().setTable(toTable);
+
+        if (port != null) {
+            resubmit.setInPort(port);
+        }
+
+        ActionResubmitBuilder actionResubmitBuilder = new ActionResubmitBuilder();
+        actionResubmitBuilder.setNxActionResubmit(resubmit.build());
+
+        ResubmitConvertor convertor = new ResubmitConvertor();
+        ActionPath ap =
+                ActionPath.NODES_NODE_TABLE_FLOW_INSTRUCTIONS_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION_EXTENSIONLIST_EXTENSION;
+
+        return convertor.convert(ActionUtil.createAction(actionResubmitBuilder.build()), ap);
+    }
+
     public static Action outputAction(NodeConnectorId id) {
-        return new OutputActionCaseBuilder().setOutputAction(
-                new OutputActionBuilder().setOutputNodeConnector(new Uri(id.getValue())).build()).build();
+        return new OutputActionCaseBuilder()
+            .setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri(id.getValue())).build()).build();
     }
 
     public static Action groupAction(Long id) {
@@ -373,12 +399,15 @@ public final class FlowUtils {
     }
 
     public static VlanMatch vlanMatch(int vlanId, boolean vlanIdPresent) {
-    return new VlanMatchBuilder().setVlanId(
-            new VlanIdBuilder().setVlanId(new VlanId(vlanId)).setVlanIdPresent(vlanIdPresent).build()).build();
+        return new VlanMatchBuilder()
+            .setVlanId(new VlanIdBuilder().setVlanId(new VlanId(vlanId)).setVlanIdPresent(vlanIdPresent).build())
+            .build();
     }
 
-    public static List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> pushVlanActions(int vlanId) {
-        List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> actions = new ArrayList<>();
+    public static List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> pushVlanActions(
+            int vlanId) {
+        List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> actions =
+                new ArrayList<>();
         actions.add(new ActionBuilder().setAction(pushVlanAction()).setOrder(0));
         actions.add(new ActionBuilder().setAction(setVlanId(vlanId)).setOrder(1));
         return actions;
@@ -388,9 +417,9 @@ public final class FlowUtils {
             int order) {
         List<ActionBuilder> actionBuilders = new ArrayList<>();
         actionBuilders.add(new ActionBuilder().setAction(popVlanAction()).setOrder(0));
-        return new InstructionBuilder().setInstruction(
-                new ApplyActionsCaseBuilder().setApplyActions(
-                        new ApplyActionsBuilder().setAction(actionList(actionBuilders)).build()).build())
+        return new InstructionBuilder()
+            .setInstruction(new ApplyActionsCaseBuilder()
+                .setApplyActions(new ApplyActionsBuilder().setAction(actionList(actionBuilders)).build()).build())
             .setOrder(order)
             .build();
     }
@@ -438,8 +467,8 @@ public final class FlowUtils {
     public static Action nxLoadRegAction(DstChoice dstChoice, BigInteger value, int endOffset, boolean groupBucket) {
         NxRegLoad r = new NxRegLoadBuilder().setDst(
                 new DstBuilder().setDstChoice(dstChoice)
-                    .setStart(Integer.valueOf(0))
-                    .setEnd(Integer.valueOf(endOffset))
+                    .setStart(0)
+                    .setEnd(endOffset)
                     .build())
             .setValue(value)
             .build();
@@ -516,14 +545,16 @@ public final class FlowUtils {
     public static Action nxMoveRegAction(SrcChoice srcChoice, DstChoice dstChoice, int endOffset, boolean groupBucket) {
         NxRegMove r = new NxRegMoveBuilder().setSrc(
                 new SrcBuilder().setSrcChoice(srcChoice)
-                    .setStart(Integer.valueOf(0))
-                    .setEnd(Integer.valueOf(endOffset))
+                    .setStart(0)
+                    .setEnd(endOffset)
                     .build())
             .setDst(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.DstBuilder().setDstChoice(
                     dstChoice)
-                .setStart(Integer.valueOf(0))
-                .setEnd(Integer.valueOf(endOffset))
+                .setStart(0)
+                .setEnd(endOffset)
                 .build())
+            .setDst(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.DstBuilder()
+                .setDstChoice(dstChoice).setStart(0).setEnd(endOffset).build())
             .build();
         if (groupBucket) {
             return new NxActionRegMoveNodesNodeGroupBucketsBucketActionsCaseBuilder().setNxRegMove(r).build();
@@ -574,9 +605,9 @@ public final class FlowUtils {
         NxOutputReg r = new NxOutputRegBuilder().setSrc(
                 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.output.reg.grouping.nx.output.reg.SrcBuilder().setSrcChoice(
                         srcChoice)
-                    .setOfsNbits(Integer.valueOf(31))
+                    .setOfsNbits(31)
                     .build())
-            .setMaxLen(Integer.valueOf(0xffff))
+            .setMaxLen(0xffff)
             .build();
         return new NxActionOutputRegNodesNodeTableFlowApplyActionsCaseBuilder().setNxOutputReg(r).build();
     }
@@ -622,69 +653,69 @@ public final class FlowUtils {
             } else {
                 key = NxmNxReg7Key.class;
             }
-            NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxReg(
-                    new NxmNxRegBuilder().setReg(rm.reg).setValue(rm.value).build()).build();
+            NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+                .setNxmNxReg(new NxmNxRegBuilder().setReg(rm.reg).setValue(rm.value).build()).build();
             extensions.add(new ExtensionListBuilder().setExtensionKey(key)
                 .setExtension(new ExtensionBuilder().addAugmentation(NxAugMatchNodesNodeTableFlow.class, am).build())
                 .build());
         }
-        GeneralAugMatchNodesNodeTableFlow m = new GeneralAugMatchNodesNodeTableFlowBuilder().setExtensionList(
-                extensions).build();
+        GeneralAugMatchNodesNodeTableFlow m =
+                new GeneralAugMatchNodesNodeTableFlowBuilder().setExtensionList(extensions).build();
         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
     }
 
     public static void addNxNshc1RegMatch(MatchBuilder match, Long value) {
-        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNshc1(
-                new NxmNxNshc1Builder().setValue(value).build()).build();
+        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+            .setNxmNxNshc1(new NxmNxNshc1Builder().setValue(value).build()).build();
         GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxNshc1Key.class, am, match);
         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
     }
 
     public static void addNxNshc2RegMatch(MatchBuilder match, Long value) {
-        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNshc2(
-                new NxmNxNshc2Builder().setValue(value).build()).build();
+        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+            .setNxmNxNshc2(new NxmNxNshc2Builder().setValue(value).build()).build();
         GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxNshc2Key.class, am, match);
         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
     }
 
     public static void addNxNshc3RegMatch(MatchBuilder match, Long value) {
-        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNshc3(
-                new NxmNxNshc3Builder().setValue(value).build()).build();
+        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+            .setNxmNxNshc3(new NxmNxNshc3Builder().setValue(value).build()).build();
         GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxNshc3Key.class, am, match);
         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
     }
 
     public static void addNxNshc4RegMatch(MatchBuilder match, Long value) {
-        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNshc4(
-                new NxmNxNshc4Builder().setValue(value).build()).build();
+        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+            .setNxmNxNshc4(new NxmNxNshc4Builder().setValue(value).build()).build();
         GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxNshc4Key.class, am, match);
         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
     }
 
     public static void addNxTunIdMatch(MatchBuilder match, int tunId) {
-        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxTunId(
-                new NxmNxTunIdBuilder().setValue(BigInteger.valueOf(tunId)).build()).build();
+        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+            .setNxmNxTunId(new NxmNxTunIdBuilder().setValue(BigInteger.valueOf(tunId)).build()).build();
         GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxTunIdKey.class, am, match);
         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
     }
 
     public static void addNxTunIpv4DstMatch(MatchBuilder match, Ipv4Address ipv4Address) {
-        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxTunIpv4Dst(
-                new NxmNxTunIpv4DstBuilder().setIpv4Address(ipv4Address).build()).build();
+        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+            .setNxmNxTunIpv4Dst(new NxmNxTunIpv4DstBuilder().setIpv4Address(ipv4Address).build()).build();
         GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxTunIpv4DstKey.class, am, match);
         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
     }
 
     public static void addNxNsiMatch(MatchBuilder match, short nsi) {
-        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNsi(
-                new NxmNxNsiBuilder().setNsi(nsi).build()).build();
+        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+            .setNxmNxNsi(new NxmNxNsiBuilder().setNsi(nsi).build()).build();
         GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxNsiKey.class, am, match);
         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
     }
 
     public static void addNxNspMatch(MatchBuilder match, Long nsp) {
-        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNsp(
-                new NxmNxNspBuilder().setValue(nsp).build()).build();
+        NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+            .setNxmNxNsp(new NxmNxNspBuilder().setValue(nsp).build()).build();
         GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxNspKey.class, am, match);
         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
     }
@@ -701,8 +732,8 @@ public final class FlowUtils {
     }
 
     private static Action pushVlanAction() {
-        return new PushVlanActionCaseBuilder().setPushVlanAction(
-                new PushVlanActionBuilder().setEthernetType(VLAN).build()).build();
+        return new PushVlanActionCaseBuilder()
+            .setPushVlanAction(new PushVlanActionBuilder().setEthernetType(VLAN).build()).build();
     }
 
     private static Action popVlanAction() {
@@ -710,15 +741,15 @@ public final class FlowUtils {
     }
 
     private static Action setVlanId(int vlanId) {
-        return new SetVlanIdActionCaseBuilder().setSetVlanIdAction(
-                new SetVlanIdActionBuilder().setVlanId(new VlanId(vlanId)).build()).build();
+        return new SetVlanIdActionCaseBuilder()
+            .setSetVlanIdAction(new SetVlanIdActionBuilder().setVlanId(new VlanId(vlanId)).build()).build();
     }
 
     private static List<ExtensionList> getExistingGeneralAugMatchNodesNodeTableFlow(MatchBuilder match) {
         ArrayList<ExtensionList> extensions = new ArrayList<>();
         if (match.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class) != null) {
-            List<ExtensionList> existingExtensions = match.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class)
-                .getExtensionList();
+            List<ExtensionList> existingExtensions =
+                    match.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class).getExtensionList();
             if (existingExtensions != null && !existingExtensions.isEmpty()) {
                 extensions.addAll(existingExtensions);
             }
index 8c3ee06777f1efd9aa57476b08afbcd33e94e0e7..affbb3a72267b2e13ff2e004092f9326c90f7206 100755 (executable)
@@ -45,6 +45,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlanGpe;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -60,7 +61,7 @@ public class PortSecurity extends FlowTable {
 
     public PortSecurity(OfContext ctx, short tableId) {
         super(ctx);
-        this.TABLE_ID=tableId;
+        TABLE_ID=tableId;
     }
 
     @Override
@@ -72,17 +73,20 @@ public class PortSecurity extends FlowTable {
     public void sync(NodeId nodeId, OfWriter ofWriter) {
 
         // Allow traffic from tunnel ports
-        NodeConnectorId tunnelIf = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class);
-        if (tunnelIf != null)
-            ofWriter.writeFlow(nodeId, TABLE_ID, allowFromPort(tunnelIf));
+        NodeConnectorId vxLanTunnel = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class);
+        NodeConnectorId vxLanGpeTunnel = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlanGpe.class);
+        if (vxLanTunnel != null)
+            ofWriter.writeFlow(nodeId, TABLE_ID, allowFromPort(vxLanTunnel));
+        if (vxLanGpeTunnel != null)
+            ofWriter.writeFlow(nodeId, TABLE_ID, allowFromPort(vxLanGpeTunnel));
 
         // Default drop all
-        ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID));
+        ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(1, null, TABLE_ID));
 
         // Drop IP traffic that doesn't match a source IP rule
-        ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(110), FlowUtils.ARP, TABLE_ID));
-        ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(111), FlowUtils.IPv4, TABLE_ID));
-        ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(112), FlowUtils.IPv6, TABLE_ID));
+        ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(110, FlowUtils.ARP, TABLE_ID));
+        ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(111, FlowUtils.IPv4, TABLE_ID));
+        ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(112, FlowUtils.IPv6, TABLE_ID));
 
         Set<TenantId> tenantIds = new HashSet<>();
         for (Endpoint ep : ctx.getEndpointManager().getEndpointsForNode(nodeId)) {
@@ -140,7 +144,7 @@ public class PortSecurity extends FlowTable {
         FlowId flowid = FlowIdUtils.newFlowId(TABLE_ID, "allow", match);
         FlowBuilder flowb = base()
                 .setId(flowid)
-                .setPriority(Integer.valueOf(300))
+                .setPriority(300)
                 .setMatch(match)
                 .setInstructions(FlowUtils.gotoTableInstructions(ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER()));
         return flowb.build();
@@ -179,13 +183,12 @@ public class PortSecurity extends FlowTable {
                 .setInPort(ofc.getNodeConnectorId())
                 .build();
         FlowId flowid = FlowIdUtils.newFlowId(TABLE_ID, "dhcp", match);
-        Flow flow = base()
+        return base()
                 .setPriority(priority)
                 .setId(flowid)
                 .setMatch(match)
                 .setInstructions(FlowUtils.gotoTableInstructions(ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER()))
                 .build();
-        return flow;
     }
 
     private void l3flow(OfWriter ofWriter, NodeId nodeId,
@@ -196,9 +199,9 @@ public class PortSecurity extends FlowTable {
         for (L3Address l3 : ep.getL3Address()) {
             if (l3.getIpAddress() == null)
                 continue;
-            Layer3Match m = null;
-            Long etherType = null;
-            String ikey = null;
+            Layer3Match m;
+            Long etherType;
+            String ikey;
             if (l3.getIpAddress().getIpv4Address() != null) {
                 ikey = l3.getIpAddress().getIpv4Address().getValue() + "/32";
                 if (arp) {
@@ -247,7 +250,7 @@ public class PortSecurity extends FlowTable {
         Match match = new MatchBuilder().setInPort(nc).build();
         FlowId flowid = FlowIdUtils.newFlowId(TABLE_ID, "allowExternal", match);
         FlowBuilder flowb = base().setId(flowid)
-            .setPriority(Integer.valueOf(priority))
+            .setPriority(priority)
             .setMatch(match)
             .setInstructions(FlowUtils.gotoTableInstructions(ctx.getPolicyManager().getTABLEID_INGRESS_NAT()));
         return flowb.build();
@@ -264,11 +267,13 @@ public class PortSecurity extends FlowTable {
      */
     private List<Flow> popVlanTagsOnExternalPort(NodeConnectorId nc, TenantId tenantId, Integer priority) {
         List<Flow> flows = new ArrayList<>();
-        for(L2FloodDomain l2Fd : ctx.getTenant(tenantId).getTenant().getForwardingContext().getL2FloodDomain()) {
-        Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class);
-            if (segmentation != null) {
-                Integer vlanId = segmentation.getSegmentationId();
-                flows.add(buildPopVlanFlow(nc, vlanId, priority));
+        if(ctx.getTenant(tenantId) != null) {
+            for (L2FloodDomain l2Fd : ctx.getTenant(tenantId).getTenant().getForwardingContext().getL2FloodDomain()) {
+                Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class);
+                if (segmentation != null) {
+                    Integer vlanId = segmentation.getSegmentationId();
+                    flows.add(buildPopVlanFlow(nc, vlanId, priority));
+                }
             }
         }
         return flows;
index 923fe3eaa7666290939ffa5163181b5faa0577c6..74c046f9453c7cc3d9553e8435f000fcadd219ee 100644 (file)
@@ -20,6 +20,7 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev1407
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.ServiceFunctionPaths;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPath;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPathKey;
+import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.sfc.of.renderer.rev151123.SfcOfRendererConfig;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public class SfcIidFactory {
@@ -30,23 +31,28 @@ public class SfcIidFactory {
 
     public static InstanceIdentifier<ServiceFunctionChain> sfcIid(SfcName sfcName) {
 
-        ServiceFunctionChainKey serviceFunctionChainKey =
-                new ServiceFunctionChainKey(sfcName);
+        ServiceFunctionChainKey serviceFunctionChainKey = new ServiceFunctionChainKey(sfcName);
         return InstanceIdentifier.builder(ServiceFunctionChains.class)
-                .child(ServiceFunctionChain.class, serviceFunctionChainKey).build();
+            .child(ServiceFunctionChain.class, serviceFunctionChainKey)
+            .build();
     }
 
     public static InstanceIdentifier<ServiceFunctionPath> sfpIid(SfpName sfpName) {
 
         ServiceFunctionPathKey serviceFunctionPathKey = new ServiceFunctionPathKey(sfpName);
         return InstanceIdentifier.builder(ServiceFunctionPaths.class)
-                .child(ServiceFunctionPath.class, serviceFunctionPathKey).build();
+            .child(ServiceFunctionPath.class, serviceFunctionPathKey)
+            .build();
     }
 
     public static InstanceIdentifier<RenderedServicePath> rspIid(RspName rspName) {
 
         RenderedServicePathKey rspKey = new RenderedServicePathKey(rspName);
-        return InstanceIdentifier.builder(RenderedServicePaths.class)
-                .child(RenderedServicePath.class, rspKey).build();
+        return InstanceIdentifier.builder(RenderedServicePaths.class).child(RenderedServicePath.class, rspKey).build();
+    }
+
+    public static InstanceIdentifier<SfcOfRendererConfig> sfcOfRendererConfigIid() {
+        return InstanceIdentifier.builder(SfcOfRendererConfig.class).build();
+
     }
 }
index 52b06e5aebeb3886b75fb7af80efedd3480f6a81..ae4aeb1610c8696862f1370c4b79ba2b41a918c7 100644 (file)
@@ -132,6 +132,12 @@ module ofoverlay {
         }
     }
 
+    /* 
+    * TODO: should add "portname" to this instead of using heuristic name.
+    * Then SwitchManager could pull from here potentially. The only things that should
+    * populate this are REST or OVSDB-Neutron ... but now we could listen on OVSDB for when
+    * an SFF creates this for us and use the same tunnel... 
+    */
     augment "/inv:nodes/inv:node" {
         ext:augment-identifier "of-overlay-node-config";
         list tunnel {
index 0cae3198be2c1adccd12b4fec8ed442d688400fe..3beb8b3aacf480493b7dfff1e78fbcdae3331d16 100644 (file)
@@ -22,6 +22,7 @@ import java.util.concurrent.ScheduledExecutorService;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.InOrder;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
@@ -33,6 +34,7 @@ import org.opendaylight.groupbasedpolicy.dto.EgKey;
 import org.opendaylight.groupbasedpolicy.dto.EpKey;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
@@ -45,7 +47,12 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DataStoreHelper.class})
 public class PolicyManagerTest {
 
     // constant values used by the tested class implementation
@@ -70,7 +77,7 @@ public class PolicyManagerTest {
     private Flow flow;
 
     @Before
-    public void setUp() {
+    public void setUp() throws Exception {
         EndpointManager endpointManager = mock(EndpointManager.class);
         ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
         dataBroker = mock(DataBroker.class);
@@ -83,9 +90,12 @@ public class PolicyManagerTest {
         readWriteTransaction = mock(ReadWriteTransaction.class);
         when(dataBroker.newReadWriteTransaction()).thenReturn(readWriteTransaction);
 
+        PowerMockito.stub(PowerMockito.method(DataStoreHelper.class, "submitToDs")).toReturn(true);
         manager = new PolicyManager(dataBroker, switchManager,
                 endpointManager, executor, tableOffset);
 
+        ///manager = mock(PolicyManager.class);
+
         nodeId = mock(NodeId.class);
         tableId = 5;
         flow = mock(Flow.class);
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/ChainActionFlowsTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/ChainActionFlowsTest.java
new file mode 100644 (file)
index 0000000..09bbcce
--- /dev/null
@@ -0,0 +1,93 @@
+/*\r
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.when;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.PolicyEnforcer.NetworkElements;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader.SfcNshHeaderBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
+\r
+public class ChainActionFlowsTest {\r
+\r
+    private SfcNshHeader sfcNshHeader;\r
+    private NodeConnectorId tunPort;\r
+    private NetworkElements netElements;\r
+    private PolicyManager policyManager;\r
+    private SwitchManager switchManager;\r
+    private Ipv4Address ip1 = new Ipv4Address("10.1.1.1");\r
+    private Ipv4Address ip2 = new Ipv4Address("10.1.1.2");\r
+\r
+    @Before\r
+    public void setup() {\r
+        policyManager = mock(PolicyManager.class);\r
+        switchManager = mock(SwitchManager.class);\r
+        EndpointFwdCtxOrdinals ords = mock(EndpointFwdCtxOrdinals.class);\r
+        sfcNshHeader = mock(SfcNshHeader.class);\r
+        netElements = mock(NetworkElements.class);\r
+        when(netElements.getSrcNodeId()).thenReturn(new NodeId("openflow:1"));\r
+        when(netElements.getSrcEpOrdinals()).thenReturn(ords);\r
+        when(netElements.getSrcEpOrdinals().getL3Id()).thenReturn(7);\r
+        when(netElements.getDstNodeId()).thenReturn(new NodeId("openflow:1"));\r
+        when(netElements.getDstEpOrdinals()).thenReturn(ords);\r
+        when(netElements.getDstEpOrdinals().getL3Id()).thenReturn(7);\r
+        when(netElements.getLocalNodeId()).thenReturn(new NodeId("openflow:1"));\r
+        tunPort = new NodeConnectorId("openflow:1:42");\r
+    }\r
+\r
+    @Test\r
+    public void createExternalFlowTest() throws Exception {\r
+        // Note C1 != tunDest ie ip1 and ip2 - output action\r
+        sfcNshHeader = new SfcNshHeaderBuilder().setNshMetaC1(SfcNshHeader.convertIpAddressToLong(ip1))\r
+                .setNshTunIpDst(ip2)\r
+                .setNshMetaC2(7L)\r
+                .setNshNsiToChain((short) 1)\r
+                .build();\r
+\r
+        Flow flow = ChainActionFlows.createExternalFlow(sfcNshHeader, tunPort, netElements, policyManager, switchManager, ip2);\r
+        assertEquals(policyManager.getTABLEID_EXTERNAL_MAPPER(), flow.getTableId().shortValue());\r
+        assertTrue(flow.getInstructions().getInstruction()\r
+                .get(0).getInstruction().toString().contains("_outputAction=OutputAction"));\r
+\r
+        // Note C1 == tunDest ie ip1\r
+        sfcNshHeader = new SfcNshHeaderBuilder().setNshMetaC1(SfcNshHeader.convertIpAddressToLong(ip1))\r
+                .setNshTunIpDst(ip1)\r
+                .setNshMetaC2(7L)\r
+                .setNshNsiToChain((short) 1)\r
+                .build();\r
+\r
+        flow = ChainActionFlows.createExternalFlow(sfcNshHeader, tunPort, netElements, policyManager, switchManager, ip2);\r
+\r
+        assertTrue(flow.getInstructions().getInstruction()\r
+                .get(0).getInstruction().toString().contains("_outputAction=OutputAction"));\r
+    }\r
+\r
+    @Test\r
+    public void returnOfPortFromNodeConnectorTest() {\r
+        NodeConnectorId ncId = new NodeConnectorId("openflow:1:42");\r
+        Integer port = ChainActionFlows.returnOfPortFromNodeConnector(ncId);\r
+        assertEquals(new Integer("42"), port);\r
+\r
+        ncId = new NodeConnectorId("openflow:1");\r
+        Assert.assertNull(ChainActionFlows.returnOfPortFromNodeConnector(ncId));\r
+    }\r
+}\r
index 817585cb9584d744cf518901720a11b19675dd8b..0a63878ce4394207a1b4b203bbc5daa0cab2cd23 100755 (executable)
@@ -36,7 +36,9 @@ import java.util.Objects;
 \r
 import org.junit.Before;\r
 import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;\r
@@ -51,7 +53,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayNodeConfigBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.nodes.node.TunnelBuilder;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.PolicyBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.Contract;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;\r
@@ -59,11 +60,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg7;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
 import com.google.common.collect.ImmutableList;\r
 \r
+@RunWith(PowerMockRunner.class)\r
+@PrepareForTest({PolicyManager.class})\r
 public class DestinationMapperTest extends FlowTableTest {\r
     protected static final Logger LOG =\r
             LoggerFactory.getLogger(DestinationMapperTest.class);\r
@@ -74,6 +80,8 @@ public class DestinationMapperTest extends FlowTableTest {
     @Override\r
     @Before\r
     public void setup() throws Exception {\r
+        PowerMockito.stub(PowerMockito.method(PolicyManager.class, "setSfcTableOffset")).toReturn(true);\r
+\r
         initCtx();\r
         table = new DestinationMapper(ctx,ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER());\r
         super.setup();\r
@@ -104,7 +112,6 @@ public class DestinationMapperTest extends FlowTableTest {
                     f.getMatch().getEthernetMatch())) {\r
                 // router ARP reply\r
                 Instruction ins = f.getInstructions().getInstruction().get(0);\r
-                ins = f.getInstructions().getInstruction().get(0);\r
                 assertTrue(ins.getInstruction() instanceof ApplyActionsCase);\r
                 List<Action> actions = ((ApplyActionsCase) ins.getInstruction()).getApplyActions().getAction();\r
                 assertEquals(nxMoveEthSrcToEthDstAction(),\r
@@ -219,14 +226,13 @@ public class DestinationMapperTest extends FlowTableTest {
                             .getAddress())) {\r
                 // broadcast/multicast flow should output to group table\r
                 Instruction ins = f.getInstructions().getInstruction().get(0);\r
-                ins = f.getInstructions().getInstruction().get(0);\r
                 assertTrue(ins.getInstruction() instanceof ApplyActionsCase);\r
                 List<Action> actions = ((ApplyActionsCase) ins.getInstruction()).getApplyActions().getAction();\r
                 assertEquals(nxMoveRegTunIdAction(NxmNxReg0.class, false),\r
                         actions.get(0).getAction());\r
                 assertEquals(Integer.valueOf(0), actions.get(0).getOrder());\r
 \r
-                Long v = Long.valueOf(OrdinalFactory.getContextOrdinal(tid, fd));\r
+                Long v = (long) OrdinalFactory.getContextOrdinal(tid, fd);\r
                 assertEquals(groupAction(v), actions.get(1).getAction());\r
                 assertEquals(Integer.valueOf(1), actions.get(1).getOrder());\r
                 count += 1;\r
@@ -291,7 +297,7 @@ public class DestinationMapperTest extends FlowTableTest {
 \r
 \r
         ctx.addTenant(baseTenant().setPolicy(new PolicyBuilder(baseTenant().getPolicy()).setContract(\r
-                ImmutableList.<Contract> of(baseContract(null).build())).build()).build());\r
+                ImmutableList.of(baseContract(null).build())).build()).build());\r
         verifyDMap(remoteEp, localEp);\r
     }\r
 \r
@@ -306,7 +312,7 @@ public class DestinationMapperTest extends FlowTableTest {
         endpointManager.addEndpoint(remoteEp);\r
 \r
         ctx.addTenant(baseTenant().setPolicy(new PolicyBuilder(baseTenant().getPolicy()).setContract(\r
-                ImmutableList.<Contract> of(baseContract(null).build())).build()).build());\r
+                ImmutableList.of(baseContract(null).build())).build()).build());\r
         verifyDMap(remoteEp, localEp);\r
     }\r
 \r
index 66792f1cf921d833e96a7e42cab1385b04e40a74..a3fa8a3e7e0317f40928ab33c78916954a7233f0 100755 (executable)
@@ -10,14 +10,15 @@ package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
 
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
 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.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
@@ -34,7 +35,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeCon
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 
 import com.google.common.collect.ImmutableSet;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({PolicyManager.class})
 public class ExternalMapperTest extends FlowTableTest {
 
     private ExternalMapper mapper;
@@ -64,6 +70,8 @@ public class ExternalMapperTest extends FlowTableTest {
 
     @Before
     public void initialisation() {
+        PowerMockito.stub(PowerMockito.method(PolicyManager.class, "setSfcTableOffset")).toReturn(true);
+
         initCtx();
         tableId = 6;
         nodeId = mock(NodeId.class);
@@ -86,7 +94,7 @@ public class ExternalMapperTest extends FlowTableTest {
                 .build())
             .build();
         endpointManager.addEndpoint(l2Ep);
-        switchManager.addSwitch(nodeId,null,ImmutableSet.<NodeConnectorId>of(new NodeConnectorId("openflow:1:1")), null);
+        switchManager.addSwitch(nodeId,null,ImmutableSet.of(new NodeConnectorId("openflow:1:1")), null);
         mapper.sync(nodeId, ofWriter);
         verify(ofWriter, times(4)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
     }
index d512cf2d64171dfa90e4c7af29922fb3b6e2c537..ba22da00c1a8503b8613bbc620f37bbae548fd7b 100755 (executable)
@@ -16,7 +16,6 @@ import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtil
 import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.instructions;
 import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxOutputRegAction;
 
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -27,10 +26,12 @@ import java.util.Set;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.opendaylight.groupbasedpolicy.dto.ConditionGroup;
 import org.opendaylight.groupbasedpolicy.dto.EgKey;
 import org.opendaylight.groupbasedpolicy.dto.PolicyInfo;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.RegMatch;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.PolicyEnforcer.PolicyPair;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
@@ -56,7 +57,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.conditions.ConditionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.PolicyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.Contract;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.ContractBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.ClauseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.Subject;
@@ -80,19 +80,22 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg0Key;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg2Key;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({PolicyManager.class})
 public class PolicyEnforcerTest extends FlowTableTest {
 
-    protected static final Logger LOG = LoggerFactory.getLogger(PolicyEnforcerTest.class);
-
     @Override
     @Before
     public void setup() throws Exception {
+        PowerMockito.stub(PowerMockito.method(PolicyManager.class, "setSfcTableOffset")).toReturn(true);
+
         initCtx();
         table = new PolicyEnforcer(ctx, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER());
         super.setup();
@@ -123,7 +126,7 @@ public class PolicyEnforcerTest extends FlowTableTest {
         Endpoint ep2 = localEP().setMacAddress(new MacAddress("00:00:00:00:00:02")).build();
         endpointManager.addEndpoint(ep2);
         ctx.addTenant(baseTenant().setPolicy(new PolicyBuilder(baseTenant().getPolicy())
-            .setContract(ImmutableList.<Contract>of(baseContract(null).build())).build()).build());
+            .setContract(ImmutableList.of(baseContract(null).build())).build()).build());
 
         OfWriter fm = dosync(null);
         assertNotEquals(0, fm.getTableForNode(nodeId, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER())
@@ -149,10 +152,10 @@ public class PolicyEnforcerTest extends FlowTableTest {
 
     @Test
     public void testDifferentEg() throws Exception {
-        assertEquals(7, doTestDifferentEg(ImmutableList.<Subject>of(baseSubject(null).build())));
-        assertEquals(7, doTestDifferentEg(ImmutableList.<Subject>of(baseSubject(Direction.Bidirectional).build())));
-        assertEquals(5, doTestDifferentEg(ImmutableList.<Subject>of(baseSubject(Direction.In).build())));
-        assertEquals(5, doTestDifferentEg(ImmutableList.<Subject>of(baseSubject(Direction.Out).build())));
+        assertEquals(7, doTestDifferentEg(ImmutableList.of(baseSubject(null).build())));
+        assertEquals(7, doTestDifferentEg(ImmutableList.of(baseSubject(Direction.Bidirectional).build())));
+        assertEquals(5, doTestDifferentEg(ImmutableList.of(baseSubject(Direction.In).build())));
+        assertEquals(5, doTestDifferentEg(ImmutableList.of(baseSubject(Direction.Out).build())));
     }
 
     @Test
@@ -160,36 +163,36 @@ public class PolicyEnforcerTest extends FlowTableTest {
         Rule rule1 = new RuleBuilder().setActionRef(
                 ImmutableList.of(new ActionRefBuilder().setName(new ActionName("allow")).build()))
             .setClassifierRef(
-                    createClassifierRefs(ImmutableMap.<String, Direction>of("tcp_dst_80", Direction.In, "tcp_src_80",
+                    createClassifierRefs(ImmutableMap.of("tcp_dst_80", Direction.In, "tcp_src_80",
                             Direction.In)))
             .build();
         Rule rule2 = new RuleBuilder().setActionRef(
                 ImmutableList.of(new ActionRefBuilder().setName(new ActionName("allow")).build()))
             .setClassifierRef(
-                    createClassifierRefs(ImmutableMap.<String, Direction>of("tcp_dst_80", Direction.In, "tcp_src_80",
+                    createClassifierRefs(ImmutableMap.of("tcp_dst_80", Direction.In, "tcp_src_80",
                             Direction.Out)))
             .build();
         Rule rule3 = new RuleBuilder().setActionRef(
                 ImmutableList.of(new ActionRefBuilder().setName(new ActionName("allow")).build()))
             .setClassifierRef(
-                    createClassifierRefs(ImmutableMap.<String, Direction>of("tcp_dst_80", Direction.In, "tcp_src_80",
+                    createClassifierRefs(ImmutableMap.of("tcp_dst_80", Direction.In, "tcp_src_80",
                             Direction.Out, "ether_type", Direction.In)))
             .build();
         Rule rule4 = new RuleBuilder().setActionRef(
                 ImmutableList.of(new ActionRefBuilder().setName(new ActionName("allow")).build()))
             .setClassifierRef(
-                    createClassifierRefs(ImmutableMap.<String, Direction>of("tcp_dst_80", Direction.In, "tcp_dst_90",
+                    createClassifierRefs(ImmutableMap.of("tcp_dst_80", Direction.In, "tcp_dst_90",
                             Direction.In)))
             .build();
 
         assertEquals(5,
-                doTestDifferentEg(ImmutableList.<Subject>of(createSubject("s1", ImmutableList.<Rule>of(rule1)))));
+                doTestDifferentEg(ImmutableList.of(createSubject("s1", ImmutableList.of(rule1)))));
         assertEquals(11,
-                doTestDifferentEg(ImmutableList.<Subject>of(createSubject("s2", ImmutableList.<Rule>of(rule2)))));
+                doTestDifferentEg(ImmutableList.of(createSubject("s2", ImmutableList.of(rule2)))));
         assertEquals(9,
-                doTestDifferentEg(ImmutableList.<Subject>of(createSubject("s3", ImmutableList.<Rule>of(rule3)))));
+                doTestDifferentEg(ImmutableList.of(createSubject("s3", ImmutableList.of(rule3)))));
         assertEquals(3,
-                doTestDifferentEg(ImmutableList.<Subject>of(createSubject("s4", ImmutableList.<Rule>of(rule4)))));
+                doTestDifferentEg(ImmutableList.of(createSubject("s4", ImmutableList.of(rule4)))));
     }
 
     private int doTestDifferentEg(List<Subject> subjects) throws Exception {
@@ -198,16 +201,14 @@ public class PolicyEnforcerTest extends FlowTableTest {
         Endpoint ep2 = localEP().setMacAddress(new MacAddress("00:00:00:00:00:02")).setEndpointGroup(eg2).build();
         endpointManager.addEndpoint(ep2);
         ctx.addTenant(baseTenant().setPolicy(new PolicyBuilder(baseTenant().getPolicy())
-            .setContract(ImmutableList.<Contract>of(baseContract(subjects).build())).build()).build());
+            .setContract(ImmutableList.of(baseContract(subjects).build())).build()).build());
 
         OfWriter fm = dosync(null);
         assertNotEquals(0, fm.getTableForNode(nodeId, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER())
             .getFlow()
             .size());
         int count = 0;
-        HashMap<String, Flow> flowMap = new HashMap<>();
         for (Flow f : fm.getTableForNode(nodeId, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER()).getFlow()) {
-            flowMap.put(f.getId().getValue(), f);
             if (isAllowSameEpg(f)) {
                 count += 1;
             } else if (f.getMatch() != null && Objects.equals(tunnelId, f.getMatch().getInPort())) {
@@ -221,11 +222,11 @@ public class PolicyEnforcerTest extends FlowTableTest {
                         .getType()
                         .getValue())
                     && f.getMatch().getIpMatch() != null
-                    && Objects.equals(Short.valueOf((short) 6), f.getMatch().getIpMatch().getIpProtocol())
+                    && Objects.equals((short) 6, f.getMatch().getIpMatch().getIpProtocol())
                     && f.getMatch().getLayer4Match() != null
-                    && (Objects.equals(new PortNumber(Integer.valueOf(80)),
+                    && (Objects.equals(new PortNumber(80),
                             ((TcpMatch) f.getMatch().getLayer4Match()).getTcpSourcePort()) || Objects.equals(
-                            new PortNumber(Integer.valueOf(80)),
+                            new PortNumber(80),
                             ((TcpMatch) f.getMatch().getLayer4Match()).getTcpDestinationPort()))) {
                 count += 1;
             } else if (f.getMatch() != null
@@ -236,11 +237,11 @@ public class PolicyEnforcerTest extends FlowTableTest {
                         .getType()
                         .getValue())
                     && f.getMatch().getIpMatch() != null
-                    && Objects.equals(Short.valueOf((short) 6), f.getMatch().getIpMatch().getIpProtocol())
+                    && Objects.equals((short) 6, f.getMatch().getIpMatch().getIpProtocol())
                     && f.getMatch().getLayer4Match() != null
-                    && (Objects.equals(new PortNumber(Integer.valueOf(80)),
+                    && (Objects.equals(new PortNumber(80),
                             ((TcpMatch) f.getMatch().getLayer4Match()).getTcpSourcePort()) || Objects.equals(
-                            new PortNumber(Integer.valueOf(80)),
+                            new PortNumber(80),
                             ((TcpMatch) f.getMatch().getLayer4Match()).getTcpDestinationPort()))) {
                 count += 1;
             }
@@ -298,9 +299,9 @@ public class PolicyEnforcerTest extends FlowTableTest {
         assertNotEquals(cg1Id, cg2Id);
 
         MatchBuilder mb = new MatchBuilder();
-        FlowUtils.addNxRegMatch(mb, RegMatch.of(NxmNxReg0.class, Long.valueOf(eg1Id)),
-                RegMatch.of(NxmNxReg1.class, Long.valueOf(cg1Id)), RegMatch.of(NxmNxReg2.class, Long.valueOf(eg2Id)),
-                RegMatch.of(NxmNxReg3.class, Long.valueOf(cg2Id)));
+        FlowUtils.addNxRegMatch(mb, RegMatch.of(NxmNxReg0.class, (long) eg1Id),
+                RegMatch.of(NxmNxReg1.class, (long) cg1Id), RegMatch.of(NxmNxReg2.class, (long) eg2Id),
+                RegMatch.of(NxmNxReg3.class, (long) cg2Id));
         int count = 0;
         OfWriter fm = dosync(null);
         assertEquals(7, fm.getTableForNode(nodeId, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER())
@@ -379,8 +380,8 @@ public class PolicyEnforcerTest extends FlowTableTest {
         providerCondGrpId = 8;
         consumerEicIp = mock(IpPrefix.class);
         providerEicIp = mock(IpPrefix.class);
-        consumerEicIpPrefixes = new HashSet<IpPrefix>(Arrays.asList(consumerEicIp));
-        providerEicIpPrefixes = new HashSet<IpPrefix>(Arrays.asList(providerEicIp));
+        consumerEicIpPrefixes = new HashSet<>(Collections.singletonList(consumerEicIp));
+        providerEicIpPrefixes = new HashSet<>(Collections.singletonList(providerEicIp));
         consumerEpNodeId = mock(NodeId.class);
         when(consumerEpNodeId.getValue()).thenReturn("consumerValue");
         providerEpNodeId = mock(NodeId.class);
@@ -407,8 +408,8 @@ public class PolicyEnforcerTest extends FlowTableTest {
 
         policyPair = new PolicyPair(consumerEpgId, providerEpgId, consumerCondGrpId, providerCondGrpId,
                 consumerEicIpPrefixes, providerEicIpPrefixes, consumerEpNodeId, providerEpNodeId);
-        Assert.assertTrue(policyPair.equals(policyPair));
-        Assert.assertFalse(policyPair.equals(null));
+
+        Assert.assertNotNull(policyPair);
         Assert.assertFalse(policyPair.equals(new Object()));
 
         Assert.assertFalse(other.equals(policyPair));
index 58562bcb7133ed08503be8b0bd7d28a785e85415..4fba089868c9cfbec01043fc6e1ce2d41f6797af 100755 (executable)
@@ -17,7 +17,9 @@ import java.util.Set;
 \r
 import org.junit.Before;\r
 import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;\r
@@ -34,17 +36,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
 \r
 import com.google.common.collect.ImmutableList;\r
 import com.google.common.collect.ImmutableSet;\r
 \r
 import static org.junit.Assert.*;\r
 \r
+@RunWith(PowerMockRunner.class)\r
+@PrepareForTest({PolicyManager.class})\r
 public class PortSecurityTest extends FlowTableTest {\r
-    protected static final Logger LOG =\r
-            LoggerFactory.getLogger(PortSecurityTest.class);\r
 \r
     private Endpoint ep = localEP()\r
             .setL3Address(ImmutableList.of(new L3AddressBuilder()\r
@@ -57,6 +60,8 @@ public class PortSecurityTest extends FlowTableTest {
     @Override\r
     @Before\r
     public void setup() throws Exception {\r
+        PowerMockito.stub(PowerMockito.method(PolicyManager.class, "setSfcTableOffset")).toReturn(true);\r
+\r
         initCtx();\r
         table = new PortSecurity(ctx,ctx.getPolicyManager().getTABLEID_PORTSECURITY());\r
         super.setup();\r
@@ -209,6 +214,5 @@ public class PortSecurityTest extends FlowTableTest {
                             .setNodeConnectorId(new NodeConnectorId("openflow:12:1"))\r
                             .build())).build());\r
         ctx.addTenant(baseTenant().build());\r
-        OfWriter fm = dosync(null);\r
     }\r
 }\r