1 # Copyright 2019 ZTE Corporation.
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.
16 from rest_framework import serializers
18 from lcm.ns.serializers.sol.pub_serializers import LinkSerializer
19 from lcm.ns.serializers.sol.cp_serializers import CpProtocolDataSerializer, CpProtocolInfoSerializer, VnfExtCpInfoSerializer
20 from lcm.ns.serializers.sol.resource_handle import ResourceHandleSerializer
21 from lcm.ns.serializers.sol.ext_virtual_link_info import ExtVirtualLinkInfoSerializer
22 from lcm.ns.serializers.sol.ext_managed_virtual_link_info import ExtManagedVirtualLinkInfo, VnfLinkPortInfo
23 from lcm.ns.serializers.sol.pub_serializers import AffinityOrAntiAffinityRuleSerializer
26 INSTANTIATION_STATE = [
32 class VnfScaleInfoSerializer(serializers.Serializer):
33 aspectlId = serializers.Serializer(help_text="The scaling aspect", required=True)
34 scaleLevel = serializers.Serializer(help_text="The scale level for that aspect", required=True)
37 class NsScaleInfoSerializer(serializers.Serializer):
38 nsScalingAspectId = serializers.CharField(help_text="Identifier of the NS scaling aspect.", required=True)
39 nsScaleLevelId = serializers.CharField(help_text="Identifier of the NS scale level.", required=True)
42 class VnfcCpInfo(serializers.Serializer):
43 id = serializers.CharField(
44 help_text="Identifier of the external CP instance and the related information instance.",
49 cpdId = serializers.CharField(
50 help_text="Identifier of the external CPD, VnfExtCpd, in the VNFD.",
55 vnfExtCpId = serializers.CharField(
56 help_text="When the VNFC CP is exposed as external CP of the VNF, the identifier of this external VNF CP.",
61 cpProtocolInfo = CpProtocolInfoSerializer(
62 help_text="Network protocol information for this CP.",
66 vnfLinkPortId = serializers.CharField(
67 help_text="Identifier of the vnfLinkPorts structure in the vnfVirtualLinkResourceInfo structure.",
74 class VnfcResourceInfoSerializer(serializers.Serializer):
75 id = serializers.CharField(
76 help_text="Identifier of this VnfcResourceInfo instance.",
80 vduId = serializers.CharField(
81 help_text="Reference to the applicable VDU in the VNFD.",
85 computeResource = ResourceHandleSerializer(
86 help_text="Reference to the VirtualCompute resource.",
89 storageResourceIds = serializers.ListSerializer(
90 help_text="References to the VirtualStorage resources. \
91 The value refers to a VirtualStorageResourceInfo item in the VnfInstance.",
92 child=serializers.CharField(help_text="Identifier In Vnf", allow_blank=True),
95 reservationId = serializers.CharField(
96 help_text="The reservation identifier applicable to the resource.",
101 vnfcCpInfo = VnfcCpInfo(
102 help_text="CPs of the VNFC instance. \
103 Shall be present when that particular CP of the VNFC instance is associated to an external CP of the VNF instance.",
107 metadata = serializers.DictField(
108 help_text="Metadata about this resource.",
109 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
114 # class VnfLinkPortInfo(serializers.Serializer):
115 # id = serializers.CharField(
116 # help_text="Identifier of this link port as provided by the entity that has created the link port.",
121 # resourceHandle = ResourceHandleSerializer(
122 # help_text="Reference to the virtualised network resource realizing this link port.",
125 # cpInstanceId = serializers.CharField(
126 # help_text="When the link port is used for external connectivity by the VNF, \
127 # this attribute represents the identifier of the external CP of the VNF to be connected to this link port.",
134 class VnfVirtualLinkResourceInfoSerializer(serializers.Serializer):
135 id = serializers.CharField(
136 help_text="Identifier of this VnfVirtualLinkResourceInfo instance.",
141 virtualLinkDescId = serializers.CharField(
142 help_text="Identifier of the VNF Virtual Link Descriptor (VLD) in the VNFD.",
147 networkResource = ResourceHandleSerializer(
148 help_text="Reference to the VirtualNetwork resource.",
151 reservationId = serializers.CharField(
152 help_text="The reservation identifier applicable to the resource.",
157 vnfLinkPorts = VnfLinkPortInfo(
158 help_text="Links ports of this VL. \
159 Shall be present when the linkPort is used for external connectivity by the VNF",
163 metadata = serializers.DictField(
164 help_text="Metadata about this resource.",
165 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
170 class VirtualStorageResourceInfoSerializer(serializers.Serializer):
171 id = serializers.CharField(
172 help_text="Identifier of this VirtualStorageResourceInfo instance.",
177 virtualStorageDescId = serializers.CharField(
178 help_text="Identifier of the VirtualStorageDesc in the VNFD.",
183 storageResource = ResourceHandleSerializer(
184 help_text="Reference to the VirtualStorage resource.",
187 reservationId = serializers.CharField(
188 help_text="The reservation identifier applicable to the resource.",
193 metadata = serializers.DictField(
194 help_text="Metadata about this resource.",
195 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
200 class InstantiatedVnfInfo(serializers.Serializer):
201 flavourId = serializers.CharField(
202 help_text="Identifier of the VNF deployment flavour applied to this VNF instance.",
207 vnfState = serializers.ChoiceField(
208 help_text="State of the VNF instance.",
209 choices=["STARTED", "STOPPED"],
213 scaleStatus = VnfScaleInfoSerializer(
214 help_text="Scale status of the VNF, one entry per aspect. \
215 Represents for every scaling aspect how big the VNF has been scaled w.r.t. that aspect.",
219 extCpInfo = VnfExtCpInfoSerializer(
220 help_text="Information about the external CPs exposed by the VNF instance.",
224 extVirtualLinkInfo = ExtVirtualLinkInfoSerializer(
225 help_text="Information about the external VLs the VNF instance is connected to.",
229 extManagedVirtualLinkInfo = ExtManagedVirtualLinkInfo(
230 help_text="Information about the externally-managed inner VLs of the VNF instance.",
234 monitoringParameters = serializers.DictField(
235 help_text="Active monitoring parameters.",
236 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
239 localizationLanguage = serializers.CharField(
240 help_text="Information about localization language of the VNF.",
245 vnfcResourceInfo = VnfcResourceInfoSerializer(
246 help_text="Information about the virtualised compute and storage resources used by the VNFCs of the VNF instance.",
250 vnfVirtualLinkResourceInfo = VnfVirtualLinkResourceInfoSerializer(
251 help_text="Information about the virtualised network resources used by the VLs of the VNF instance.",
255 virtualStorageResourceInfo = VirtualStorageResourceInfoSerializer(
256 help_text="Information about the virtualised storage resources used as storage for the VNF instance.",
262 class VnfInstanceLinks(serializers.Serializer):
263 href = LinkSerializer(
264 help_text="URI of this resource.",
267 indicators = LinkSerializer(
268 help_text="Indicators related to this VNF instance.",
271 instantiate = LinkSerializer(
272 help_text="Link to the instantiate task resource.",
275 termiante = LinkSerializer(
276 help_text="Link to the terminate task resource.",
279 scale = LinkSerializer(
280 help_text="Link to the scale task resource.",
283 scaleToLevel = LinkSerializer(
284 help_text="Link to the scale_to_level task resource.",
287 changeFlavour = LinkSerializer(
288 help_text="Link to the change_flavour task resource.",
291 heal = LinkSerializer(
292 help_text="Link to the heal task resource.",
295 operate = LinkSerializer(
296 help_text="Link to the operate task resource.",
299 changeExtConn = LinkSerializer(
300 help_text="Link to the change_ext_conn task resource.",
305 class VnfInstanceSerializer(serializers.Serializer):
306 id = serializers.CharField(
307 help_text="Identifier of the VNF instance.",
312 vnfInstanceName = serializers.CharField(
313 help_text="Name of the VNF instance.",
318 vnfInstanceDescription = serializers.CharField(
319 help_text="Human-readable description of the VNF instance.",
323 vnfdId = serializers.CharField(
324 help_text="Identifier of the VNFD on which the VNF instance is based.",
329 vnfProvider = serializers.CharField(
330 help_text="Provider of the VNF and the VNFD.",
335 vnfProductName = serializers.CharField(
336 help_text="Name to identify the VNF Product.",
341 vnfSoftwareVersion = serializers.CharField(
342 help_text="Software version of the VNF.",
347 vnfdVersion = serializers.CharField(
348 help_text="Identifies the version of the VNFD.",
353 vnfPkgId = serializers.CharField(
354 help_text="Identifier of information held by the NFVO about the specific VNF package on which the VNF is based. \
355 This attribute can be modified with the PATCH method.",
360 vnfConfigurableProperties = serializers.DictField(
361 help_text="Current values of the configurable properties of the VNF instance. \
362 Configurable properties referred in this attribute are declared in the VNFD",
363 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
366 vimId = serializers.ListField(
367 help_text="Identifier set of a VIM that manages resources for the VNF instance.",
368 child=serializers.CharField(help_text="Identifier of a VIM that manages resources for the VNF instance.", allow_null=False),
370 instantiationState = serializers.ChoiceField(
371 help_text="The instantiation state of the VNF.",
372 choices=INSTANTIATION_STATE,
376 instantiatedVnfInfo = InstantiatedVnfInfo(
377 help_text="Information specific to an instantiated VNF instance. \
378 This attribute shall be present if the instantiateState attribute value is INSTANTIATED",
381 metadata = serializers.DictField(
382 help_text="Additional VNF-specific metadata describing the VNF instance.\
383 This attribute can be modified with the PATCH method.",
384 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
387 extensions = serializers.DictField(
388 help_text="VNF-specific attributes that affect the lifecycle management of this VNF instance by the VNFM, or the lifecycle management scripts. \
389 This attribute can be modified with the PATCH method.",
390 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
393 _links = VnfInstanceLinks(
394 help_text="Links to resources related to this resource.",
399 class PnfExtCpInfoSerializer(serializers.Serializer):
400 cpInstanceId = serializers.CharField(help_text="Identifier of the CP in the scope of the PNF.",
403 cpdId = serializers.CharField(help_text="Identifier of (reference to) the Connection Point Descriptor"
404 "(CPD) for this CP.", required=True)
406 cpProtocolData = CpProtocolDataSerializer(help_text="Parameters for configuring the network protocols on"
407 "the CP.", required=True, many=True)
410 class PnfInfoSerializer(serializers.Serializer):
411 pnfId = serializers.CharField(help_text="Identifier of the PNF.", required=True)
412 pnfName = serializers.CharField(help_text="Name of the PNF.", required=True)
413 pnfdId = serializers.CharField(help_text="Identifier of the PNFD on which the PNF is based.", required=True)
414 pnfdInfoId = serializers.CharField(help_text="Identifier of the PNFD information onject related to this PNF.", required=True)
415 pnfProfileId = serializers.CharField(help_text="Identifier of the related PnfProfile in the NSD on which the PNF is based.", required=True)
416 cpInfo = PnfExtCpInfoSerializer(help_text="Information on the external CP of the PNF", required=True, many=True)
419 class NsLinkPortInfo(serializers.Serializer):
420 id = serializers.CharField(
421 help_text="Identifier of this link port as provided by the entity that has created the link port.",
426 resourceHandle = ResourceHandleSerializer(
427 help_text="Reference to the virtualised resource realizing this link port.",
430 cpInstanceId = serializers.CharField(
431 help_text="Identifier of the external CP of the VNF connected to this link port. \
432 There shall be at most one link port associated with any external connection point instance.",
439 class NsVirtualLinkInfoSerializer(serializers.Serializer):
440 id = serializers.CharField(help_text="Identifier of the VL instance.", required=True)
441 nsVirtualLinkDescId = serializers.CharField(help_text="Identifier of the VLD in the NSD.", required=True)
442 nsVirtualLinkProfileId = serializers.CharField(help_text="Identifier of the VL profile in the NSD.", required=True)
443 resourceHandle = ResourceHandleSerializer(help_text="Identifier(s) of the virtualised network resource(s) realizing the VL instance", required=True, many=True)
444 linkPort = NsLinkPortInfo(help_text="Link ports of this VL.", many=True, required=False, allow_null=True)
447 class NsCpHandleSerializer(serializers.Serializer):
448 vnfInstanceId = serializers.CharField(help_text="Identifier of the VNF instance associated to the CP"
449 "instance.", required=False, allow_null=True)
450 vnfExtCpInstanceId = serializers.CharField(help_text="Identifier of the VNF external CP instance in the"
451 "scope of the VNF instance.",
452 required=False, allow_null=True)
453 pnfInfoId = serializers.CharField(help_text="Identifier of the PNF instance associated to the CP"
454 "instance.", required=False, allow_null=True)
455 pnfExtCpInstanceId = serializers.CharField(help_text="Identifier of the PNF external CP instance in the"
456 "scope of the PNF.", required=False, allow_null=True)
457 nsInstanceId = serializers.CharField(help_text="Identifier of the NS instance associated to the SAP"
458 "instance", required=False, allow_null=True)
459 nsSapInstanceId = serializers.CharField(help_text="Identifier of the SAP instance in the scope of the NS"
460 "instance.", required=False, allow_null=True)
463 class MaskSerializer(serializers.Serializer):
464 startingPoint = serializers.CharField(help_text="Indicates the offset between the last bit of the source"
465 "mac address and the first bit of the sequence of bits"
466 "to be matched.", required=True)
467 length = serializers.CharField(help_text="Indicates the number of bits to be matched", required=True)
468 value = serializers.CharField(help_text="Provide the sequence of bit values to be matched.",
472 class NfpRuleSerializer(serializers.Serializer):
473 etherDestinationAddress = serializers.CharField(help_text="Indicates a destination Mac address",
474 required=False, allow_null=True)
475 etherSourceAddress = serializers.CharField(help_text="Indicates a source Mac address",
476 required=False, allow_null=True)
477 etherType = serializers.ChoiceField(help_text="Indicates the protocol carried over the Ethernet layer",
478 choices=["IPV4", "IPV6"], required=False, allow_null=True)
479 vlanTag = serializers.ListField(help_text="ndicates a VLAN identifier in an IEEE 802.1Q-2014 tag",
480 required=False, allow_null=True)
481 protocol = serializers.ChoiceField(help_text="Indicates the L4 protocol, For IPv4 [7] this corresponds to"
482 "the field called Protocol to identifythe next level "
483 "protocol", choices=["TCP", "UDP", "ICMP"],
484 required=False, allow_null=True)
485 dscp = serializers.CharField(help_text="For IPv4 [7] a string of 0 and 1 digits that corresponds to the"
486 "6-bit Differentiated Services Code Point (DSCP) field of the"
487 "IP header.", required=False, allow_null=True)
488 sourcePortRange = serializers.CharField(help_text="Indicates a range of source ports",
489 required=False, allow_null=True)
490 destinationPortRange = serializers.CharField(help_text="Indicates a range of destination ports",
491 required=False, allow_null=True)
492 sourceIpAddressPrefix = serializers.CharField(help_text="Indicates the source IP address range in CIDR"
493 "format.", required=False, allow_null=True)
494 destinationIpAddressPrefix = serializers.CharField(help_text="Indicates the destination IP address range"
496 required=False, allow_null=True)
497 extendedCriteria = MaskSerializer(help_text="Indicates values of specific bits in a frame",
498 required=False, allow_null=True, many=True)
501 class NfpInfoSerializer(serializers.Serializer):
502 id = serializers.CharField(help_text="Identifier of this NFP instance.", required=True)
503 nfpdId = serializers.CharField(help_text="Identifier of the NFPD used to instantiate this NFP"
504 "instance.", required=False, allow_null=True)
505 nfpName = serializers.CharField(help_text="Human readable name for the NFP instance.",
506 required=False, allow_null=True)
507 description = serializers.CharField(help_text="Human readable description for the NFP instance.",
509 nscpHandle = NsCpHandleSerializer(help_text="Identifier(s) of the CPs and/or SAPs which the NFP "
510 "passes by", required=True, many=True)
511 totalCp = serializers.CharField(help_text="Total number of CP and SAP instances in this NFP"
512 "instance.", required=False, allow_null=True)
513 nfpRule = NfpRuleSerializer(help_text="The NfpRule data type is an expression of the conditions that "
514 "shall be met in order for the NFP to be applicable to the packet",
516 nfpState = serializers.ChoiceField(help_text="The state of the NFP instance.",
517 choices=["ENABLED", "DISABLED"], required=True)
520 class VnffgInfoSerializer(serializers.Serializer):
521 id = serializers.CharField(help_text="Identifier of this VNFFG instance.", required=True)
522 vnffgdId = serializers.CharField(help_text="Identifier of the VNFFGD in the NSD.", required=True)
523 vnfInstanceId = serializers.ListField(help_text="Identifier(s) of the constituent VNF instance(s) of this"
525 child=serializers.CharField(help_text="ID of vnf instance"),
527 pnfInfoId = serializers.ListField(help_text="Identifier(s) of the constituent PNF instance(s) of this"
529 child=serializers.CharField(help_text="ID of pnf info"),
530 required=False, allow_null=True)
531 nsVirtualLinkInfoId = serializers.ListField(help_text="Identifier(s) of the constituent VL instance(s) of"
532 "thisVNFFG instance.",
533 child=serializers.CharField(
534 help_text="ID of ns virtual link info"), required=True)
535 nsCpHandle = NsCpHandleSerializer(help_text="Identifiers of the CP instances attached to the "
536 "constituent VNFs and PNFs or the SAP instances of "
537 "the VNFFG.", required=True, allow_null=False, many=True)
538 nfpInfo = NfpInfoSerializer(help_text="Information on the NFP instances.",
539 required=True, allow_null=False, many=True)
542 class SapInfo(serializers.Serializer):
543 id = serializers.CharField(
544 help_text="Identifier of the SAP instance.",
546 sapdId = serializers.CharField(
547 help_text="Reference to the SAPD for this SAP.",
549 sapName = serializers.CharField(
550 help_text="Human readable name for the SAP.",
552 description = serializers.CharField(
553 help_text="Human readable description for the SAP. ",
555 sapProtocolInfo = CpProtocolInfoSerializer(
556 help_text="Parameters for configuring the network protocols on the SAP.",
562 class NsLinkSerializer(serializers.Serializer):
563 self = LinkSerializer(
564 help_text="URI of this resource.",
566 nestedNsInstances = LinkSerializer(
567 help_text="Links to the nested NS instances of the present NS instance.",
570 instantiate = LinkSerializer(
571 help_text="Link to the instantiate task resource.",
574 terminate = LinkSerializer(
575 help_text="Link to the terminate task resource.",
578 update = LinkSerializer(
579 help_text="Link to the update task resource.",
582 scale = LinkSerializer(
583 help_text="Link to the scale task resource.",
586 heal = LinkSerializer(
587 help_text="Link to the heal task resource.",
592 class NsInstanceSerializer(serializers.Serializer):
593 id = serializers.CharField(
594 help_text="Identifier of the NS instance.",
596 nsInstanceName = serializers.CharField(
597 help_text="Human readable name of the NS instance.",
599 nsInstanceDescription = serializers.CharField(
600 help_text="Human readable description of the NS instance.",
602 nsdId = serializers.CharField(
603 help_text="Identifier of the NSD on which the NS instance is based.",
605 nsdInfoId = serializers.CharField(
606 help_text="Identifier of the NSD information object on which the NS instance is based.",
608 flavourId = serializers.CharField(
609 help_text="Identifier of the NS deployment flavour applied to the NS instance.",
611 vnfInstance = VnfInstanceSerializer(
612 help_text="Information on constituent VNF(s) of the NS instance.",
615 pnfInfo = PnfInfoSerializer(
616 help_text="Information on constituent PNF(s) of the NS instance.",
619 virtualLinkInfo = NsVirtualLinkInfoSerializer(
620 help_text="Information on the VL(s) of the NS instance.",
623 vnffgInfo = VnffgInfoSerializer(
626 help_text="VNF Forward Graph Information.")
630 help_text="Create data concerning the SAPs.")
631 nestedNsInstanceId = serializers.ListField(
632 help_text="Identifier of the nested NS(s) of the NS instance.",
633 child=serializers.CharField(),
637 nsState = serializers.ChoiceField(
638 help_text="The state of the NS instance.",
639 choices=["NOT_INSTANTIATED", "INSTANTIATED"],
642 nsScaleStatus = NsScaleInfoSerializer(
643 help_text="Status of each NS scaling aspect declared in the applicable DF.",
647 additionalAffinityOrAntiAffinityRule = AffinityOrAntiAffinityRuleSerializer(
651 help_text="Specifies additional affinity or anti-affinity constraint for the VNF instances to be instantiated as part of the NS instantiation.")
652 _links = NsLinkSerializer(help_text="The links of the NS instance.", required=True)