Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from common.proto.context_pb2 import SliceList
from context.client.ContextClient import ContextClient
from nbi.service.rest_server.nbi_plugins.ietf_network_slice.ietf_slice_handler import (
IETFSliceHandler,
)
context_client = ContextClient()
with open("nbi/tests/data/slice/post_network_slice1.json", mode="r") as f:
post_slice_request = json.load(f)
with open("nbi/tests/data/slice/post_sdp_to_network_slice1.json", mode="r") as f:
post_sdp_request = json.load(f)
with open("nbi/tests/data/slice/post_connection_group_to_network_slice1.json", mode="r") as f:
post_connection_group_request = json.load(f)
with open("nbi/tests/data/slice/post_match_criteria_to_sdp1_in_slice1.json", mode="r") as f:
post_match_criteria_request = json.load(f)
slice_1 = None
def select_slice(*args) -> SliceList:
slice_list = SliceList()
slice_list.slices.extend([slice_1])
return slice_list
def test_create_slice():
global slice_1
slice_1 = IETFSliceHandler.create_slice_service(post_slice_request)
ietf_data = json.loads(slice_1.slice_config.config_rules[0].custom.resource_value)
assert ietf_data == post_slice_request
assert slice_1.slice_endpoint_ids[0].device_id.device_uuid.uuid == "172.16.204.220"
assert slice_1.slice_endpoint_ids[1].device_id.device_uuid.uuid == "172.16.104.221"
assert slice_1.slice_id.slice_uuid.uuid == "slice1"
def test_create_sdp(monkeypatch):
global slice_1
monkeypatch.setattr(context_client, "SelectSlice", select_slice)
slice_1 = IETFSliceHandler.create_sdp(post_sdp_request, "slice1", context_client)
ietf_data = json.loads(slice_1.slice_config.config_rules[0].custom.resource_value)
slice_services = ietf_data["network-slice-services"]["slice-service"]
slice_service = slice_services[0]
slice_sdps = slice_service["sdps"]["sdp"]
assert len(slice_sdps) == 3
def test_create_connection_group(monkeypatch):
global slice_1
monkeypatch.setattr(context_client, "SelectSlice", select_slice)
slice_1 = IETFSliceHandler.create_connection_group(post_connection_group_request, "slice1", context_client)
ietf_data = json.loads(slice_1.slice_config.config_rules[0].custom.resource_value)
slice_services = ietf_data["network-slice-services"]["slice-service"]
slice_service = slice_services[0]
slice_connection_groups = slice_service["connection-groups"]["connection-group"]
assert slice_connection_groups[0]['id'] == 'line1'
assert slice_connection_groups[1]['id'] == 'line2'
assert len(slice_connection_groups) == 2
def test_create_match_criteria(monkeypatch):
global slice_1
monkeypatch.setattr(context_client, "SelectSlice", select_slice)
slice_1 = IETFSliceHandler.create_match_criteria(post_match_criteria_request, "slice1", "1", context_client)
ietf_data = json.loads(slice_1.slice_config.config_rules[0].custom.resource_value)
slice_services = ietf_data["network-slice-services"]["slice-service"]
slice_service = slice_services[0]
slice_sdps = slice_service["sdps"]["sdp"]
sdp1_match_criteria = slice_sdps[0]['service-match-criteria']['match-criterion']
assert len(sdp1_match_criteria) == 2
assert sdp1_match_criteria[0]['target-connection-group-id'] == 'line1'
assert sdp1_match_criteria[1]['target-connection-group-id'] == 'line2'
assert slice_1.slice_endpoint_ids[0].device_id.device_uuid.uuid == "172.16.61.11"
assert slice_1.slice_endpoint_ids[1].device_id.device_uuid.uuid == "172.16.204.220"