1 # Copyright (c) 2018, CMCC Technologies Co., Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from rest_framework import serializers
17 from lcm.ns.serializers.pub_serializers import IpOverEthernetAddressDataSerializer, Links, ipAddressesSerializer
18 # from lcm.ns.serializers.pub_serializers import Links, IpAddressSerialzier, ipAddressesSerializer
21 class ContextSerializer(serializers.Serializer):
22 globalCustomerId = serializers.CharField(help_text="Global customer ID", required=False, allow_null=True)
23 serviceType = serializers.CharField(help_text="Service type", required=False, allow_null=True)
26 class CreateNsReqSerializer(serializers.Serializer):
27 csarId = serializers.CharField(help_text="Package ID of NS", required=False, allow_null=True)
28 nsdId = serializers.CharField(help_text="Identifier of the NSD that defines the NS instance to be"
29 "created.", required=True, allow_null=False)
30 nsName = serializers.CharField(help_text="Name of NS", required=False, allow_null=True)
31 nsDescription = serializers.CharField(help_text="Description of NS", required=False, allow_null=True)
32 context = ContextSerializer(help_text="Context of NS", required=False)
35 class VnfInstanceSerializer(serializers.Serializer):
36 id = serializers.CharField(help_text="Identifier of the VNF instance.", required=True)
37 vnfInstanceName = serializers.CharField(help_text="Name of the VNF instance.", required=False,
41 # class IpOverEthernetAddressDataSerializer(serializers.Serializer):
42 # macAddress = serializers.CharField(help_text="Mac address", required=False, allow_null=True)
43 # ipAddresses = IpAddressSerialzier(help_text="List of IP addresses to assign to the extCP instance.",
44 # required=False, allow_null=True, many=True)
47 class cpProtocolDataSerializer(serializers.Serializer):
48 layerProtocol = serializers.ChoiceField(help_text="Identifier of layer(s) and protocol(s).",
49 choices=["IP_OVER_ETHERNET"], required=True, allow_null=False)
50 ipOverEthernet = IpOverEthernetAddressDataSerializer(help_text="Network address data for IP over Ethernet"
51 " to assign to the extCP instance.",
52 required=False, allow_null=True)
55 class PnfExtCpInfoSerializer(serializers.Serializer):
56 cpInstanceId = serializers.CharField(help_text="Identifier of the CP in the scope of the PNF.",
59 cpdId = serializers.CharField(help_text="Identifier of (reference to) the Connection Point Descriptor"
60 "(CPD) for this CP.", required=True)
62 cpProtocolData = cpProtocolDataSerializer(help_text="Parameters for configuring the network protocols on"
63 "the CP.", required=True, many=True)
66 class PnfInfoSerializer(serializers.Serializer):
67 pnfId = serializers.CharField(help_text="Identifier of the PNF.", required=True)
68 pnfName = serializers.CharField(help_text="Name of the PNF.", required=True)
69 pnfdId = serializers.CharField(help_text="Identifier of the PNFD on which the PNF is based.",
72 pnfdInfoId = serializers.CharField(help_text="Identifier of the PNFD information onject related to this "
73 "PNF.", required=True)
74 pnfProfileId = serializers.CharField(help_text="Identifier of the related PnfProfile in the NSD on which "
75 "the PNF is based.", required=True)
77 cpInfo = PnfExtCpInfoSerializer(help_text="Information on the external CP of the PNF",
78 required=True, many=True)
81 class ResourceHandleSerializer(serializers.Serializer):
82 vimId = serializers.CharField(help_text="Identifier of the VIM under whose control this resource is"
83 "placed.", required=False, allow_null=True)
84 resourceProviderId = serializers.CharField(help_text="Identifier of the entity responsible for the"
85 "management of the resource", required=False,
87 resourceId = serializers.CharField(help_text="Identifier of the resource in the scope of the VIM or the "
88 "resource provider.", required=True)
89 vimLevelResourceType = serializers.CharField(help_text="Type of the resource in the scope of the VIM or"
90 "the resource provider",
91 required=False, allow_null=True)
94 class NsVirtualLinkInfoSerializer(serializers.Serializer):
95 id = serializers.CharField(help_text="Identifier of the VL instance.", required=True)
96 nsVirtualLinkDescId = serializers.CharField(help_text="Identifier of the VLD in the NSD.", required=True)
97 resourceHandle = ResourceHandleSerializer(help_text="Identifier(s) of the virtualised network resource(s)"
98 " realizing the VL instance",
99 required=True, many=True)
102 class NsCpHandleSerializer(serializers.Serializer):
103 vnfInstanceId = serializers.CharField(help_text="Identifier of the VNF instance associated to the CP"
104 "instance.", required=False, allow_null=True)
105 vnfExtCpInstanceId = serializers.CharField(help_text="Identifier of the VNF external CP instance in the"
106 "scope of the VNF instance.",
107 required=False, allow_null=True)
108 pnfInfoId = serializers.CharField(help_text="Identifier of the PNF instance associated to the CP"
109 "instance.", required=False, allow_null=True)
110 pnfExtCpInstanceId = serializers.CharField(help_text="Identifier of the PNF external CP instance in the"
111 "scope of the PNF.", required=False, allow_null=True)
112 nsInstanceId = serializers.CharField(help_text="Identifier of the NS instance associated to the SAP"
113 "instance", required=False, allow_null=True)
114 nsSapInstanceId = serializers.CharField(help_text="Identifier of the SAP instance in the scope of the NS"
115 "instance.", required=False, allow_null=True)
118 class MaskSerializer(serializers.Serializer):
119 startingPoint = serializers.CharField(help_text="Indicates the offset between the last bit of the source"
120 "mac address and the first bit of the sequence of bits"
121 "to be matched.", required=True)
122 length = serializers.CharField(help_text="Indicates the number of bits to be matched", required=True)
123 value = serializers.CharField(help_text="Provide the sequence of bit values to be matched.",
127 class NfpRuleSerializer(serializers.Serializer):
128 etherDestinationAddress = serializers.CharField(help_text="Indicates a destination Mac address",
129 required=False, allow_null=True)
130 etherSourceAddress = serializers.CharField(help_text="Indicates a source Mac address",
131 required=False, allow_null=True)
132 etherType = serializers.ChoiceField(help_text="Indicates the protocol carried over the Ethernet layer",
133 choices=["IPV4", "IPV6"], required=False, allow_null=True)
134 vlanTag = serializers.ListField(help_text="ndicates a VLAN identifier in an IEEE 802.1Q-2014 tag",
135 required=False, allow_null=True)
136 protocol = serializers.ChoiceField(help_text="Indicates the L4 protocol, For IPv4 [7] this corresponds to"
137 "the field called Protocol to identifythe next level "
138 "protocol", choices=["TCP", "UDP", "ICMP"],
139 required=False, allow_null=True)
140 dscp = serializers.CharField(help_text="For IPv4 [7] a string of 0 and 1 digits that corresponds to the"
141 "6-bit Differentiated Services Code Point (DSCP) field of the"
142 "IP header.", required=False, allow_null=True)
143 sourcePortRange = serializers.CharField(help_text="Indicates a range of source ports",
144 required=False, allow_null=True)
145 destinationPortRange = serializers.CharField(help_text="Indicates a range of destination ports",
146 required=False, allow_null=True)
147 sourceIpAddressPrefix = serializers.CharField(help_text="Indicates the source IP address range in CIDR"
148 "format.", required=False, allow_null=True)
149 destinationIpAddressPrefix = serializers.CharField(help_text="Indicates the destination IP address range"
151 required=False, allow_null=True)
152 extendedCriteria = MaskSerializer(help_text="Indicates values of specific bits in a frame",
153 required=False, allow_null=True, many=True)
156 class NfpInfoSerializer(serializers.Serializer):
157 id = serializers.CharField(help_text="Identifier of this NFP instance.", required=True)
158 nfpdId = serializers.CharField(help_text="Identifier of the NFPD used to instantiate this NFP"
159 "instance.", required=False, allow_null=True)
160 nfpName = serializers.CharField(help_text="Human readable name for the NFP instance.",
161 required=False, allow_null=True)
162 description = serializers.CharField(help_text="Human readable description for the NFP instance.",
164 nscpHandle = NsCpHandleSerializer(help_text="Identifier(s) of the CPs and/or SAPs which the NFP "
165 "passes by", required=True, many=True)
166 totalCp = serializers.CharField(help_text="Total number of CP and SAP instances in this NFP"
167 "instance.", required=False, allow_null=True)
168 nfpRule = NfpRuleSerializer(help_text="The NfpRule data type is an expression of the conditions that "
169 "shall be met in order for the NFP to be applicable to the packet",
171 nfpState = serializers.ChoiceField(help_text="The state of the NFP instance.",
172 choices=["ENABLED", "DISABLED"], required=True)
175 class VnffgInfoSerializer(serializers.Serializer):
176 id = serializers.CharField(help_text="Identifier of this VNFFG instance.", required=True)
177 vnffgdId = serializers.CharField(help_text="Identifier of the VNFFGD in the NSD.", required=True)
178 vnfInstanceId = serializers.ListField(help_text="Identifier(s) of the constituent VNF instance(s) of this"
180 child=serializers.CharField(help_text="ID of vnf instance"),
182 pnfInfoId = serializers.ListField(help_text="Identifier(s) of the constituent PNF instance(s) of this"
184 child=serializers.CharField(help_text="ID of pnf info"),
185 required=False, allow_null=True)
186 nsVirtualLinkInfoId = serializers.ListField(help_text="Identifier(s) of the constituent VL instance(s) of"
187 "thisVNFFG instance.",
188 child=serializers.CharField(
189 help_text="ID of ns virtual link info"), required=True)
190 nsCpHandle = NsCpHandleSerializer(help_text="Identifiers of the CP instances attached to the "
191 "constituent VNFs and PNFs or the SAP instances of "
192 "the VNFFG.", required=True, allow_null=False, many=True)
193 nfpInfo = NfpInfoSerializer(help_text="Information on the NFP instances.",
194 required=True, allow_null=False, many=True)
197 class IpOverEthernetAddressInfoSerializer(serializers.Serializer):
198 macAddress = serializers.CharField(help_text="Assigned MAC address", required=True)
199 ipAddresses = ipAddressesSerializer(help_text="Addresses assigned to the CP or SAP instance.",
200 required=False, allow_null=True, many=True)
203 class CpProtocolInfoSerializer(serializers.Serializer):
204 layerProtocol = serializers.ChoiceField(help_text="The identifier of layer(s) and protocol(s) associated"
205 "to the network address information.",
206 choices=["IP_OVER_ETHERNET"], required=True)
207 ipOverEthernet = IpOverEthernetAddressInfoSerializer(help_text="IP addresses over Ethernet to assign to"
208 "the CPor SAP instance.",
209 required=False, allow_null=True)
212 class SapInfoSerializer(serializers.Serializer):
213 id = serializers.CharField(help_text="Identifier of the SAP instance.", required=True)
214 sapdId = serializers.CharField(help_text="Identifier of the SAPD in the NSD.", required=True)
215 sapName = serializers.CharField(help_text="Human readable name for the SAP instance.", required=True)
216 description = serializers.CharField(help_text="Human readable description for the SAP instance.",
218 sapProtocolInfo = CpProtocolInfoSerializer(help_text="Network protocol information for this SAP.",
219 required=True, many=True)
222 class NsScaleInfoSerializer(serializers.Serializer):
223 nsScalingAspectId = serializers.CharField(help_text="Identifier of the NS scaling aspect.", required=True)
224 nsScaleLevelId = serializers.CharField(help_text="Identifier of the NS scale level.", required=True)
227 class AffinityOrAntiAffinityRuleSerializer(serializers.Serializer):
228 vnfdId = serializers.ListField(help_text="Reference to a VNFD.",
229 child=serializers.CharField(help_text="Identifier of the vnfd"),
230 required=False, allow_null=True)
231 vnfProfileId = serializers.ListField(help_text="Reference to a vnfProfile defined in the NSD.",
232 child=serializers.CharField(
233 help_text="Identifier of the vnfProfile"), required=True)
234 vnfInstanceId = serializers.ListField(help_text="Reference to the existing VNF instance as the subject of"
235 "the affinity or anti-affinity rule",
236 child=serializers.CharField(help_text="identifier of the"
238 required=False, allow_null=True)
239 affinityOrAntiAffiinty = serializers.ChoiceField(help_text="The type of the constraint.",
240 choices=["AFFINITY", "ANTI_AFFINITY"], required=True)
241 scope = serializers.ChoiceField(help_text="Specifies the scope of the rule where the placement"
242 "constraint applies.",
243 choices=["NFVI_POP", "ZONE", "ZONE_GROUP", "NFVI_NODE"], required=True)
246 class CreateNsRespSerializer(serializers.Serializer):
247 nsInstanceId = serializers.CharField(help_text="ID of NS instance", required=True)
248 nsInstanceName = serializers.CharField(help_text="Human readable name of the NS instance.", required=True)
249 nsInstanceDescription = serializers.CharField(help_text="Human readable description of the NS instance.",
251 nsdId = serializers.CharField(help_text="Identifier of the NSD on which the NS instance is based.",
253 nsdInfoId = serializers.CharField(help_text="Identifier of the NSD information object on which the "
254 "NS instance is based.", required=True)
255 flavourId = serializers.CharField(help_text="Identifier of the NS deployment flavour applied to "
256 "the NS instance.", required=False, allow_null=True)
257 vnfInstance = VnfInstanceSerializer(help_text="Information on constituent VNF(s) of the NS instance.",
258 required=False, allow_null=True, many=True)
260 pnfInfo = PnfInfoSerializer(help_text="Information on the PNF(s) that are part of the NS instance.",
261 required=False, allow_null=True, many=True)
262 virtualLinkInfo = NsVirtualLinkInfoSerializer(help_text="Information on the VL(s) of the NS instance.",
263 required=False, allow_null=True, many=True)
264 vnffgInfo = VnffgInfoSerializer(help_text="Information on the VNFFG(s) of the NS instance",
265 required=False, allow_null=True, many=True)
266 sapInfo = SapInfoSerializer(help_text="Information on the SAP(s) of the NS instance",
267 required=False, allow_null=True, many=True)
268 nestedNsInstanceId = serializers.ListField(help_text="Identifier of the nested NS(s) of the NS instance.",
269 child=serializers.CharField(help_text="nested of the NS"
271 required=False, allow_null=True)
272 nsState = serializers.ChoiceField(help_text="The state of the NS instance.", required=True,
273 choices=["NOT_INSTANTIATED", "INSTANTIATED"])
274 nsScaleStatus = NsScaleInfoSerializer(help_text="Status of each NS scaling aspect declared in the"
275 "applicable DF, how 'big' the NS instance has been"
276 "scaled w.r.t. that aspect.",
277 required=False, allow_null=True, many=True)
278 additionalAffinityOrAntiAffinityRule = AffinityOrAntiAffinityRuleSerializer(
279 help_text="Information on the additional affinity or anti-affinity rule from NS instantiation "
280 "operation.", required=False, allow_null=True, many=True)
281 _links = Links(help_text="Links to resources related to this resource.", required=True)