From df8be52ac73ef042d16862e6020dbd6c7a9612cd Mon Sep 17 00:00:00 2001 From: Cong Phuoc Hoang Date: Wed, 25 Jul 2018 15:29:08 +0900 Subject: [PATCH] Add 'symmetrical' as property of a forwarding path When Network Service (NS) is supported in Tacker, we can launch multiple VNFFGs by initiating NS. Because each VNFFG can have different 'symmetrical' value, we should support dynamic 'symmetrical' parameter for each VNFFG in VNFFG descriptor. This feature will add 'symmetrical' as a property of forwarding path, so users can set 'symmetrical' value to 'true' or 'false' to change symmetrical value of a port chain in networking-sfc. Change-Id: Ie9a6abe96141954e95902cd426abafa10d744236 --- contrib/tacker-config/ns-clean.sh | 12 +++-- contrib/tacker-config/ns-config.sh | 2 + doc/source/user/nsd_usage_guide.rst | 2 + doc/source/user/vnffg_usage_guide.rst | 50 +++++++++++++------ ...erty-forwarding-path-b7e6568b19ece356.yaml | 6 +++ .../tosca-templates/vnffg-nsd/ns_param.yaml | 5 +- .../vnffg-nsd/tosca-multiple-vnffg-nsd.yaml | 3 ++ .../vnffg-nsd/tosca-single-vnffg-nsd.yaml | 6 ++- ...osca-vnffgd-legacy-symmetrical-sample.yaml | 1 + .../tosca-vnffgd-symmetrical-sample.yaml | 1 + .../vnffgd/vnffg-param-file.yaml | 9 ++-- tacker/db/nfvo/vnffg_db.py | 17 ++++++- tacker/tests/unit/db/utils.py | 19 +++---- tacker/tests/unit/nfvo/test_nfvo_plugin.py | 9 +--- tacker/tosca/lib/tacker_nfv_defs.yaml | 6 +++ 15 files changed, 102 insertions(+), 46 deletions(-) create mode 100644 releasenotes/notes/add-symmetrical-as-property-forwarding-path-b7e6568b19ece356.yaml diff --git a/contrib/tacker-config/ns-clean.sh b/contrib/tacker-config/ns-clean.sh index 82f5a1ce5..dc67b1073 100755 --- a/contrib/tacker-config/ns-clean.sh +++ b/contrib/tacker-config/ns-clean.sh @@ -12,11 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -echo "Deleting network service NS1" -network_service_id=$(openstack ns list | grep NS1 | awk '{print $2}') -if [ -n "$network_service_id" ]; then - openstack ns delete $network_service_id -fi +echo "Deleting network service NS1, NS2" +for ns in NS1 NS2; do + network_service_id=$(openstack ns list | grep $ns | awk '{print $2}') + if [ -n "$network_service_id" ]; then + openstack ns delete $network_service_id + fi +done sleep 5 diff --git a/contrib/tacker-config/ns-config.sh b/contrib/tacker-config/ns-config.sh index 456caf105..10eb72d0b 100755 --- a/contrib/tacker-config/ns-config.sh +++ b/contrib/tacker-config/ns-config.sh @@ -31,6 +31,7 @@ sleep 15 client_ip=$(openstack server list | grep http_client | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+') network_source_port_id=$(openstack port list | grep $client_ip | awk '{print $2}') ip_dst=$(openstack server list | grep http_server | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+') +network_dest_port_id=$(openstack port list | grep $ip_dst | awk '{print $2}') echo "Creating/ Updating ns_param.yaml file" cat > ../../samples/tosca-templates/vnffg-nsd/ns_param.yaml << EOL @@ -39,6 +40,7 @@ nsd: vl2_name: net0 net_src_port_id: ${network_source_port_id} ip_dest_prefix: ${ip_dst}/24 + net_dst_port_id: ${network_dest_port_id} EOL vim_default=$(openstack vim list | grep openstack | awk '{print $10}') diff --git a/doc/source/user/nsd_usage_guide.rst b/doc/source/user/nsd_usage_guide.rst index 777ad4b3b..a93a8e540 100644 --- a/doc/source/user/nsd_usage_guide.rst +++ b/doc/source/user/nsd_usage_guide.rst @@ -326,6 +326,7 @@ VNFFG. description: creates path inside ns (src_port->CP12->CP22->dst_port) properties: id: 51 + symmetrical: true policy: type: ACL criteria: @@ -346,6 +347,7 @@ VNFFG. description: creates path inside ns (src_port->CP12->CP22->dst_port) properties: id: 52 + symmetrical: false policy: type: ACL criteria: diff --git a/doc/source/user/vnffg_usage_guide.rst b/doc/source/user/vnffg_usage_guide.rst index 0afef58cd..bb61108ae 100644 --- a/doc/source/user/vnffg_usage_guide.rst +++ b/doc/source/user/vnffg_usage_guide.rst @@ -123,14 +123,32 @@ without "symmetrical", you can ommit "network_dst_port_id" and "ip_dst_prefix". .. code-block:: yaml - policy: - type: ACL - criteria: - - network_src_port_id: 640dfd77-c92b-45a3-b8fc-22712de480e1 - network_dst_port_id: ea206bba-7083-4364-a9f1-c0b7fdf61b6e - destination_port_range: 80-1024 - ip_proto: 6 - ip_dst_prefix: 192.168.1.2/24 + Forwarding_path1: + type: tosca.nodes.nfv.FP.TackerV2 + description: creates path (CP12->CP22) + properties: + id: 51 + symmetrical: true + policy: + type: ACL + criteria: + - name: block_tcp + classifier: + network_src_port_id: 640dfd77-c92b-45a3-b8fc-22712de480e1 + network_dst_port_id: ea206bba-7083-4364-a9f1-c0b7fdf61b6e + ip_dst_prefix: 192.168.1.2/24 + destination_port_range: 80-1024 + ip_proto: 6 + path: + - forwarder: VNFD1 + capability: CP12 + - forwarder: VNFD2 + capability: CP22 + +In above template, users can set **symmetrical** in properties of a forwarding +path create symmetrical VNFFG. If this property is not set, **symmetrical** +will be specified by **--symmetrical** in create VNFFG command (default value +is False). You can use the sample VNFFGD template for symmetrical feature (in port chain) such as this `link CP2) properties: id: 52 + symmetrical: false policy: type: ACL criteria: diff --git a/releasenotes/notes/add-symmetrical-as-property-forwarding-path-b7e6568b19ece356.yaml b/releasenotes/notes/add-symmetrical-as-property-forwarding-path-b7e6568b19ece356.yaml new file mode 100644 index 000000000..786da21a4 --- /dev/null +++ b/releasenotes/notes/add-symmetrical-as-property-forwarding-path-b7e6568b19ece356.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + This feature adds 'symmetrical' as a property of forwarding path, + so users can set 'symmetrical' value to 'true' or 'false' to change + the symmetrical value of a port chain in networking-sfc. diff --git a/samples/tosca-templates/vnffg-nsd/ns_param.yaml b/samples/tosca-templates/vnffg-nsd/ns_param.yaml index 2d68a7b36..a9c1686e6 100644 --- a/samples/tosca-templates/vnffg-nsd/ns_param.yaml +++ b/samples/tosca-templates/vnffg-nsd/ns_param.yaml @@ -1,5 +1,6 @@ nsd: vl1_name: net_mgmt vl2_name: net0 - net_src_port_id: 22566484-6585-483b-9f70-0c2811895f96 - ip_dest_prefix: 10.10.0.11/24 + net_src_port_id: 5610a59a-68d3-431b-aa11-843744e81041 + ip_dest_prefix: 10.10.0.5/24 + net_dst_port_id: 0eed8399-6c51-4eee-b037-0999c93ac898 diff --git a/samples/tosca-templates/vnffg-nsd/tosca-multiple-vnffg-nsd.yaml b/samples/tosca-templates/vnffg-nsd/tosca-multiple-vnffg-nsd.yaml index 45facb483..c09ccc8cd 100644 --- a/samples/tosca-templates/vnffg-nsd/tosca-multiple-vnffg-nsd.yaml +++ b/samples/tosca-templates/vnffg-nsd/tosca-multiple-vnffg-nsd.yaml @@ -48,12 +48,14 @@ topology_template: description: creates path inside ns (src_port->CP12->CP22->dst_port) properties: id: 51 + symmetrical: true policy: type: ACL criteria: - name: block_tcp classifier: network_src_port_id: {get_input: net_src_port_id} + network_dst_port_id: {get_input: net_dst_port_id} destination_port_range: 80-1024 ip_proto: 6 ip_dst_prefix: {get_input: ip_dest_prefix} @@ -68,6 +70,7 @@ topology_template: description: creates path inside ns (src_port->CP12->dst_port) properties: id: 52 + symmetrical: false policy: type: ACL criteria: diff --git a/samples/tosca-templates/vnffg-nsd/tosca-single-vnffg-nsd.yaml b/samples/tosca-templates/vnffg-nsd/tosca-single-vnffg-nsd.yaml index 30e5ec907..a4be14e52 100644 --- a/samples/tosca-templates/vnffg-nsd/tosca-single-vnffg-nsd.yaml +++ b/samples/tosca-templates/vnffg-nsd/tosca-single-vnffg-nsd.yaml @@ -18,6 +18,9 @@ topology_template: net_src_port_id: type: string description: neutron port id of source port + net_dst_port_id: + type: string + description: neutron port id of destination port ip_dest_prefix: type: string description: IP prefix of destination port @@ -48,12 +51,14 @@ topology_template: description: creates path inside ns (src_port->CP12->CP22->dst_port) properties: id: 51 + symmetrical: true policy: type: ACL criteria: - name: block_tcp classifier: network_src_port_id: {get_input: net_src_port_id} + network_dst_port_id: {get_input: net_dst_port_id} destination_port_range: 80-1024 ip_proto: 6 ip_dst_prefix: {get_input: ip_dest_prefix} @@ -64,7 +69,6 @@ topology_template: capability: CP22 groups: - VNFFG1: type: tosca.groups.nfv.VNFFG description: HTTP to Corporate Net diff --git a/samples/tosca-templates/vnffgd/tosca-vnffgd-legacy-symmetrical-sample.yaml b/samples/tosca-templates/vnffgd/tosca-vnffgd-legacy-symmetrical-sample.yaml index 999a38b7f..cdb4eca36 100644 --- a/samples/tosca-templates/vnffgd/tosca-vnffgd-legacy-symmetrical-sample.yaml +++ b/samples/tosca-templates/vnffgd/tosca-vnffgd-legacy-symmetrical-sample.yaml @@ -11,6 +11,7 @@ topology_template: description: creates path (CP12->CP22) properties: id: 51 + symmetrical: true policy: type: ACL criteria: diff --git a/samples/tosca-templates/vnffgd/tosca-vnffgd-symmetrical-sample.yaml b/samples/tosca-templates/vnffgd/tosca-vnffgd-symmetrical-sample.yaml index c05ff7798..353066763 100644 --- a/samples/tosca-templates/vnffgd/tosca-vnffgd-symmetrical-sample.yaml +++ b/samples/tosca-templates/vnffgd/tosca-vnffgd-symmetrical-sample.yaml @@ -11,6 +11,7 @@ topology_template: description: creates path (CP12->CP22) properties: id: 51 + symmetrical: true policy: type: ACL criteria: diff --git a/samples/tosca-templates/vnffgd/vnffg-param-file.yaml b/samples/tosca-templates/vnffgd/vnffg-param-file.yaml index d9e744e26..e0bcec5ff 100644 --- a/samples/tosca-templates/vnffgd/vnffg-param-file.yaml +++ b/samples/tosca-templates/vnffgd/vnffg-param-file.yaml @@ -1,6 +1,3 @@ -{ - net_src_port_id: 640dfd77-c92b-45a3-b8fc-22712de480e1 - dst_port_range: 80-1024 - ip_dst_pre: - - 192.168.1.2/24 -} +net_src_port_id: 640dfd77-c92b-45a3-b8fc-22712de480e1 +dst_port_range: 80-1024 +ip_dst_pre: 192.168.1.2/24 diff --git a/tacker/db/nfvo/vnffg_db.py b/tacker/db/nfvo/vnffg_db.py index ebc72590d..a04d71e4e 100644 --- a/tacker/db/nfvo/vnffg_db.py +++ b/tacker/db/nfvo/vnffg_db.py @@ -358,7 +358,9 @@ class VnffgPluginDbMixin(vnffg.VNFFGPluginBase, db_base.CommonDbMixin): vnffg_id = vnffg.get('id') or uuidutils.generate_uuid() template_id = vnffg['vnffgd_id'] ns_id = vnffg.get('ns_id', None) - symmetrical = vnffg['symmetrical'] + symmetrical_in_temp = self._get_symmetrical_template(context, vnffg) + symmetrical = symmetrical_in_temp if symmetrical_in_temp is not None \ + else vnffg.get('symmetrical') with context.session.begin(subtransactions=True): template_db = self._get_resource(context, VnffgTemplate, @@ -1336,6 +1338,19 @@ class VnffgPluginDbMixin(vnffg.VNFFGPluginBase, db_base.CommonDbMixin): if template_db.get('template_source') == 'inline': self.delete_vnffgd(context, vnffgd_id) + def _get_symmetrical_template(self, context, vnffg): + vnffgd_topo = None + if vnffg.get('vnffgd_template'): + vnffgd_topo = vnffg['vnffgd_template']['topology_template'] + elif vnffg.get('vnffgd_id'): + vnffgd_template = self.get_vnffgd(context, vnffg.get('vnffgd_id')) + vnffgd_topo = vnffgd_template['template']['vnffgd'][ + 'topology_template'] + vnffg_name = list(vnffgd_topo['groups'].keys())[0] + nfp_name = vnffgd_topo['groups'][vnffg_name]['members'][0] + fp_prop = vnffgd_topo['node_templates'][nfp_name]['properties'] + return fp_prop.get('symmetrical', None) + def _make_template_dict(self, template, fields=None): res = {} key_list = ('id', 'tenant_id', 'name', 'description', 'template', diff --git a/tacker/tests/unit/db/utils.py b/tacker/tests/unit/db/utils.py index b960a0c1c..7207932e8 100644 --- a/tacker/tests/unit/db/utils.py +++ b/tacker/tests/unit/db/utils.py @@ -256,10 +256,11 @@ def get_dummy_vnffg_param_obj(): 'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437', 'name': 'dummy_vnffg', u'attributes': { - u'template': vnffgd_tosca_param_template}, + u'template': vnffgd_tosca_param_template, + u'param_values': + yaml.safe_load(vnffg_params) + }, 'vnf_mapping': {}, - u'attributes': {u'param_values': - yaml.safe_load(vnffg_params)}, 'symmetrical': False}} @@ -269,10 +270,9 @@ def get_dummy_vnffg_str_param_obj(): 'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437', 'name': 'dummy_vnffg', u'attributes': { - u'template': vnffgd_tosca_param_template}, - 'vnf_mapping': {}, - u'attributes': { + u'template': vnffgd_tosca_param_template, u'param_values': 'value not dict format'}, + 'vnf_mapping': {}, 'symmetrical': False}} @@ -282,10 +282,11 @@ def get_dummy_vnffg_multi_param_obj(): 'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437', 'name': 'dummy_vnffg', u'attributes': { - u'template': vnffgd_tosca_multi_param_template}, + u'template': vnffgd_tosca_multi_param_template, + u'param_values': + yaml.safe_load(vnffg_multi_params) + }, 'vnf_mapping': {}, - u'attributes': {u'param_values': - yaml.safe_load(vnffg_multi_params)}, 'symmetrical': False}} diff --git a/tacker/tests/unit/nfvo/test_nfvo_plugin.py b/tacker/tests/unit/nfvo/test_nfvo_plugin.py index 764b7edf1..23ebde757 100644 --- a/tacker/tests/unit/nfvo/test_nfvo_plugin.py +++ b/tacker/tests/unit/nfvo/test_nfvo_plugin.py @@ -81,10 +81,6 @@ def get_by_name(): return False -def get_by_id(): - return False - - def dummy_get_vim_auth(*args, **kwargs): return {'vim_auth': {u'username': u'admin', 'password': 'devstack', u'project_name': u'nfv', u'user_id': u'', @@ -757,12 +753,11 @@ class TestNfvoPlugin(db_base.SqlTestCase): symmetrical=mock.ANY ) - @mock.patch.object(nfvo_plugin.NfvoPlugin, '_get_by_id') - def test_create_vnffg_param_value_format_error(self, mock_get_by_id): + def test_create_vnffg_param_value_format_error(self): with patch.object(TackerManager, 'get_service_plugins') as \ mock_plugins: mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()} - mock_get_by_id.value = get_by_id() + self._insert_dummy_vnffg_param_template() vnffg_obj = utils.get_dummy_vnffg_str_param_obj() self.assertRaises(nfvo.VnffgParamValueFormatError, self.nfvo_plugin.create_vnffg, diff --git a/tacker/tosca/lib/tacker_nfv_defs.yaml b/tacker/tosca/lib/tacker_nfv_defs.yaml index 6e745ca80..6f3582ce4 100644 --- a/tacker/tosca/lib/tacker_nfv_defs.yaml +++ b/tacker/tosca/lib/tacker_nfv_defs.yaml @@ -305,6 +305,9 @@ node_types: id: type: integer required: false + symmetrical: + type: boolean + required: false policy: type: tosca.nfv.datatypes.policyTypeV2 required: false @@ -321,6 +324,9 @@ node_types: id: type: integer required: false + symmetrical: + type: boolean + required: false policy: type: tosca.nfv.datatypes.policyType required: true