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.ns_serializers import IpAddress
18 from lcm.ns.serializers.common_Link import LinkSerializer
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 = serializers.ListField(help_text="List of IP addresses to assign to the extCP instance.",
45 help_text="List of IP addresses to assign to the extCP instance.",
46 required=True), required=False, allow_null=True, )
49 class cpProtocolDataSerializer(serializers.Serializer):
50 layerProtocol = serializers.ChoiceField(help_text="Identifier of layer(s) and protocol(s).",
51 choices=["IP_OVER_ETHERNET"], required=True)
52 ipOverEthernet = IpOverEthernetAddressDataSerializer(help_text="Network address data for IP over Ethernet"
53 " to assign to the extCP instance.",
54 required=True, many=True)
57 class PnfExtCpInfoSerializer(serializers.Serializer):
58 cpInstanceId = serializers.CharField(help_text="Identifier of the CP in the scope of the PNF.",
61 cpdId = serializers.CharField(help_text="Identifier of (reference to) the Connection Point Descriptor"
62 "(CPD) for this CP.", required=True)
64 cpProtocolData = cpProtocolDataSerializer(help_text="Parameters for configuring the network protocols on"
65 "the CP.", required=True, many=True)
68 class PnfInfoSerializer(serializers.Serializer):
69 pnfId = serializers.CharField(help_text="Identifier of the PNF.", required=True)
70 pnfName = serializers.CharField(help_text="Name of the PNF.", required=True)
71 pnfdId = serializers.CharField(help_text="Identifier of the PNFD on which the PNF is based.",
74 pnfdInfoId = serializers.CharField(help_text="Identifier of the PNFD information onject related to this "
75 "PNF.", required=True)
76 pnfProfileId = serializers.CharField(help_text="Identifier of the related PnfProfile in the NSD on which "
77 "the PNF is based.", required=True)
79 cpInfo = PnfExtCpInfoSerializer(help_text="Information on the external CP of the PNF",
80 required=True, many=True)
83 class ResourceHandleSerializer(serializers.Serializer):
84 vimId = serializers.CharField(help_text="Identifier of the VIM under whose control this resource is"
85 "placed.", required=False, allow_null=True)
86 resourceProviderId = serializers.CharField(help_text="Identifier of the entity responsible for the"
87 "management of the resource", required=False,
89 resourceId = serializers.CharField(help_text="Identifier of the resource in the scope of the VIM or the "
90 "resource provider.", required=True)
91 vimLevelResourceType = serializers.CharField(help_text="Type of the resource in the scope of the VIM or"
92 "the resource provider",
93 required=False, allow_null=True)
96 class NsVirtualLinkInfoSerializer(serializers.Serializer):
97 id = serializers.CharField(help_text="Identifier of the VL instance.", required=True)
98 nsVirtualLinkDescId = serializers.CharField(help_text="Identifier of the VLD in the NSD.", required=True)
99 resourceHandle = ResourceHandleSerializer(help_text="Identifier(s) of the virtualised network resource(s)"
100 " realizing the VL instance",
101 required=True, many=True)
104 class NsCpHandleSerializer(serializers.Serializer):
105 vnfInstanceId = serializers.CharField(help_text="Identifier of the VNF instance associated to the CP"
106 "instance.", required=False, allow_null=True)
107 vnfExtCpInstanceId = serializers.CharField(help_text="Identifier of the VNF external CP instance in the"
108 "scope of the VNF instance.",
109 required=False, allow_null=True)
110 pnfInfoId = serializers.CharField(help_text="Identifier of the PNF instance associated to the CP"
111 "instance.", required=False, allow_null=True)
112 pnfExtCpInstanceId = serializers.CharField(help_text="Identifier of the PNF external CP instance in the"
113 "scope of the PNF.", required=False, allow_null=True)
114 nsInstanceId = serializers.CharField(help_text="Identifier of the NS instance associated to the SAP"
115 "instance", required=False, allow_null=True)
116 nsSapInstanceId = serializers.CharField(help_text="Identifier of the SAP instance in the scope of the NS"
117 "instance.", required=False, allow_null=True)
120 class MaskSerializer(serializers.Serializer):
121 startingPoint = serializers.CharField(help_text="Indicates the offset between the last bit of the source"
122 "mac address and the first bit of the sequence of bits"
123 "to be matched.", required=True)
124 length = serializers.CharField(help_text="Indicates the number of bits to be matched", required=True)
125 value = serializers.CharField(help_text="Provide the sequence of bit values to be matched.",
129 class NfpRuleSerializer(serializers.Serializer):
130 etherDestinationAddress = serializers.CharField(help_text="Indicates a destination Mac address",
131 required=False, allow_null=True)
132 etherSourceAddress = serializers.CharField(help_text="Indicates a source Mac address",
133 required=False, allow_null=True)
134 etherType = serializers.ChoiceField(help_text="Indicates the protocol carried over the Ethernet layer",
135 choices=["IPV4", "IPV6"], required=False, allow_null=True)
136 vlanTag = serializers.ListField(help_text="ndicates a VLAN identifier in an IEEE 802.1Q-2014 tag",
137 required=False, allow_null=True)
138 protocol = serializers.ChoiceField(help_text="Indicates the L4 protocol, For IPv4 [7] this corresponds to"
139 "the field called Protocol to identifythe next level "
140 "protocol", choices=["TCP", "UDP", "ICMP"],
141 required=False, allow_null=True)
142 dscp = serializers.CharField(help_text="For IPv4 [7] a string of 0 and 1 digits that corresponds to the"
143 "6-bit Differentiated Services Code Point (DSCP) field of the"
144 "IP header.", required=False, allow_null=True)
145 sourcePortRange = serializers.CharField(help_text="Indicates a range of source ports",
146 required=False, allow_null=True)
147 destinationPortRange = serializers.CharField(help_text="Indicates a range of destination ports",
148 required=False, allow_null=True)
149 sourceIpAddressPrefix = serializers.CharField(help_text="Indicates the source IP address range in CIDR"
150 "format.", required=False, allow_null=True)
151 destinationIpAddressPrefix = serializers.CharField(help_text="Indicates the destination IP address range"
153 required=False, allow_null=True)
154 extendedCriteria = MaskSerializer(help_text="Indicates values of specific bits in a frame",
155 required=False, allow_null=True, many=True)
158 class NfpInfoSerializer(serializers.Serializer):
159 id = serializers.CharField(help_text="Identifier of this NFP instance.", required=True)
160 nfpdId = serializers.CharField(help_text="Identifier of the NFPD used to instantiate this NFP"
161 "instance.", required=False, allow_null=True)
162 nfpName = serializers.CharField(help_text="Human readable name for the NFP instance.",
163 required=False, allow_null=True)
164 description = serializers.CharField(help_text="Human readable description for the NFP instance.",
166 nscpHandle = NsCpHandleSerializer(help_text="Identifier(s) of the CPs and/or SAPs which the NFP "
167 "passes by", required=True, many=True)
168 totalCp = serializers.CharField(help_text="Total number of CP and SAP instances in this NFP"
169 "instance.", required=False, allow_null=True)
170 nfpRule = NfpRuleSerializer(help_text="The NfpRule data type is an expression of the conditions that "
171 "shall be met in order for the NFP to be applicable to the packet",
173 nfpState = serializers.ChoiceField(help_text="The state of the NFP instance.",
174 choices=["ENABLED", "DISABLED"], required=True)
177 class VnffgInfoSerializer(serializers.Serializer):
178 id = serializers.CharField(help_text="Identifier of this VNFFG instance.", required=True)
179 vnffgdId = serializers.CharField(help_text="Identifier of the VNFFGD in the NSD.", required=True)
180 vnfInstanceId = serializers.ListField(help_text="Identifier(s) of the constituent VNF instance(s) of this"
182 child=serializers.CharField(help_text="ID of vnf instance"),
184 pnfInfoId = serializers.ListField(help_text="Identifier(s) of the constituent PNF instance(s) of this"
186 child=serializers.CharField(help_text="ID of pnf info"),
187 required=False, allow_null=True)
188 nsVirtualLinkInfoId = serializers.ListField(help_text="Identifier(s) of the constituent VL instance(s) of"
189 "thisVNFFG instance.",
190 child=serializers.CharField(
191 help_text="ID of ns virtual link info"), required=True)
192 nsCpHandle = NsCpHandleSerializer(help_text="Identifiers of the CP instances attached to the "
193 "constituent VNFs and PNFs or the SAP instances of "
194 "the VNFFG.", required=True, allow_null=False, many=True)
195 nfpInfo = NfpInfoSerializer(help_text="Information on the NFP instances.",
196 required=True, allow_null=False, many=True)
199 class AddressRange(serializers.Serializer):
200 minAddress = serializers.IPAddressField(help_text="Lowest IP address belonging to the range.",
202 maxAddress = serializers.IPAddressField(help_text="Highest IP address belonging to the range.",
206 class ipAddressesSerializer(serializers.Serializer):
207 type = serializers.ChoiceField(help_text="The type of the IP addresses.",
208 choices=["IPV4", "IPV6"], required=True)
209 addresses = serializers.ListField(help_text="Fixed addresses assigned (from the subnet defined by "
210 "subnetId if provided)",
211 child=serializers.CharField(help_text="An IPV4 or IPV6 address."),
212 required=False, allow_null=True)
214 isDynamic = serializers.BooleanField(help_text="Indicates whether this set of addresses was assigned "
215 "dynamically (true) or based on address information "
216 "provided as input from the API consumer (false).",
217 required=False, default=True)
218 addressRange = AddressRange(help_text="An IP address range used", required=False, allow_null=True)
219 subnetId = serializers.CharField(help_text="Subnet defined by the identifier of the subnet"
220 "resource in the VIM", required=False, allow_null=True)
223 class IpOverEthernetAddressInfoSerializer(serializers.Serializer):
224 macAddress = serializers.CharField(help_text="Assigned MAC address", required=True)
225 ipAddresses = ipAddressesSerializer(help_text="Addresses assigned to the CP or SAP instance.",
226 required=False, allow_null=True, many=True)
229 class CpProtocolInfoSerializer(serializers.Serializer):
230 layerProtocol = serializers.ChoiceField(help_text="The identifier of layer(s) and protocol(s) associated"
231 "to the network address information.",
232 choices=["IP_OVER_ETHERNET"], required=True)
233 ipOverEthernet = IpOverEthernetAddressInfoSerializer(help_text="IP addresses over Ethernet to assign to"
234 "the CPor SAP instance.",
235 required=False, allow_null=True)
238 class SapInfoSerializer(serializers.Serializer):
239 id = serializers.CharField(help_text="Identifier of the SAP instance.", required=True)
240 sapdId = serializers.CharField(help_text="Identifier of the SAPD in the NSD.", required=True)
241 sapName = serializers.CharField(help_text="Human readable name for the SAP instance.", required=True)
242 description = serializers.CharField(help_text="Human readable description for the SAP instance.",
244 sapProtocolInfo = CpProtocolInfoSerializer(help_text="Network protocol information for this SAP.",
245 required=True, many=True)
248 class NsScaleInfoSerializer(serializers.Serializer):
249 nsScalingAspectId = serializers.CharField(help_text="Identifier of the NS scaling aspect.", required=True)
250 nsScaleLevelId = serializers.CharField(help_text="Identifier of the NS scale level.", required=True)
253 class AffinityOrAntiAffinityRuleSerializer(serializers.Serializer):
254 vnfdId = serializers.ListField(help_text="Reference to a VNFD.",
255 child=serializers.CharField(help_text="Identifier of the vnfd"),
256 required=False, allow_null=True)
257 vnfProfileId = serializers.ListField(help_text="Reference to a vnfProfile defined in the NSD.",
258 child=serializers.CharField(
259 help_text="Identifier of the vnfProfile"), required=True)
260 vnfInstanceId = serializers.ListField(help_text="Reference to the existing VNF instance as the subject of"
261 "the affinity or anti-affinity rule",
262 child=serializers.CharField(help_text="identifier of the"
264 required=False, allow_null=True)
265 affinityOrAntiAffiinty = serializers.ChoiceField(help_text="The type of the constraint.",
266 choices=["AFFINITY", "ANTI_AFFINITY"], required=True)
267 scope = serializers.ChoiceField(help_text="Specifies the scope of the rule where the placement"
268 "constraint applies.",
269 choices=["NFVI_POP", "ZONE", "ZONE_GROUP", "NFVI_NODE"], required=True)
272 class Links(serializers.Serializer):
273 self = LinkSerializer(help_text="URI of this resource.", required=True)
274 nestedNsInstances = LinkSerializer(help_text="Links to the nested NS instances of the present NS"
275 "instance.", required=False, allow_null=True)
276 instantiate = LinkSerializer(help_text="Link to the 'instantiate' task resource", required=False,
278 terminate = LinkSerializer(help_text="Link to the 'terminate' task resource", required=False, allow_null=True)
279 update = LinkSerializer(help_text="Link to the 'update' task resource", required=False, allow_null=True)
280 scale = LinkSerializer(help_text="Link to the 'scale' task resource", required=False, allow_null=True)
281 heal = LinkSerializer(help_text="Link to the 'heal' task resource", required=False, allow_null=True)
284 class CreateNsRespSerializer(serializers.Serializer):
285 nsInstanceId = serializers.CharField(help_text="ID of NS instance", required=True)
286 nsInstanceName = serializers.CharField(help_text="Human readable name of the NS instance.", required=True)
287 nsInstanceDescription = serializers.CharField(help_text="Human readable description of the NS instance.",
289 nsdId = serializers.CharField(help_text="Identifier of the NSD on which the NS instance is based.",
291 nsdInfoId = serializers.CharField(help_text="Identifier of the NSD information object on which the "
292 "NS instance is based.", required=True)
293 flavourId = serializers.CharField(help_text="Identifier of the NS deployment flavour applied to "
294 "the NS instance.", required=False, allow_null=True)
295 vnfInstance = VnfInstanceSerializer(help_text="Information on constituent VNF(s) of the NS instance.",
296 required=False, allow_null=True, many=True)
298 pnfInfo = PnfInfoSerializer(help_text="Information on the PNF(s) that are part of the NS instance.",
299 required=False, allow_null=True, many=True)
300 virtualLinkInfo = NsVirtualLinkInfoSerializer(help_text="Information on the VL(s) of the NS instance.",
301 required=False, allow_null=True, many=True)
302 vnffgInfo = VnffgInfoSerializer(help_text="Information on the VNFFG(s) of the NS instance",
303 required=False, allow_null=True, many=True)
304 sapInfo = SapInfoSerializer(help_text="Information on the SAP(s) of the NS instance",
305 required=False, allow_null=True, many=True)
306 nestedNsInstanceId = serializers.ListField(help_text="Identifier of the nested NS(s) of the NS instance.",
307 child=serializers.CharField(help_text="nested of the NS"
309 required=False, allow_null=True)
310 nsState = serializers.ChoiceField(help_text="The state of the NS instance.", required=True,
311 choices=["NOT_INSTANTIATED", "INSTANTIATED"])
312 nsScaleStatus = NsScaleInfoSerializer(help_text="Status of each NS scaling aspect declared in the"
313 "applicable DF, how 'big' the NS instance has been"
314 "scaled w.r.t. that aspect.",
315 required=False, allow_null=True, many=True)
316 additionalAffinityOrAntiAffinityRule = AffinityOrAntiAffinityRuleSerializer(
317 help_text="Information on the additional affinity or anti-affinity rule from NS instantiation "
318 "operation.", required=False, allow_null=True, many=True)
319 _links = Links(help_text="Links to resources related to this resource.", required=True)