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
24 from lcm.ns.enum import IPADDRESSES_TYPE, INSTANTIATION_STATE, VNF_STATE, NFP_STATE, PROTOCOL
25 from lcm.pub.utils.enumutil import enum_to_list
28 class VnfScaleInfoSerializer(serializers.Serializer):
29 aspectlId = serializers.Serializer(
30 help_text="Identifier of the scaling aspect",
32 scaleLevel = serializers.Serializer(
33 help_text="The scale level for that aspect.",
37 class NsScaleInfoSerializer(serializers.Serializer):
38 nsScalingAspectId = serializers.CharField(
39 help_text="Identifier of the NS scaling aspect.",
41 nsScaleLevelId = serializers.CharField(
42 help_text="Identifier of the NS scale level.",
46 class VnfcCpInfo(serializers.Serializer):
47 id = serializers.CharField(
48 help_text="Identifier of the external CP instance and the related information instance.",
50 cpdId = serializers.CharField(
51 help_text="Identifier of the external CPD, VnfExtCpd, in the VNFD.",
53 vnfExtCpId = serializers.CharField(
54 help_text="When the VNFC CP is exposed as external CP of the VNF, the identifier of this external VNF CP.",
56 cpProtocolInfo = CpProtocolInfoSerializer(
57 help_text="Network protocol information for this CP.",
60 vnfLinkPortId = serializers.CharField(
61 help_text="Identifier of the vnfLinkPorts structure in the vnfVirtualLinkResourceInfo structure.",
65 class VnfcResourceInfoSerializer(serializers.Serializer):
66 id = serializers.CharField(
67 help_text="Identifier of this VnfcResourceInfo instance.",
71 vduId = serializers.CharField(
72 help_text="Reference to the applicable VDU in the VNFD.",
76 computeResource = ResourceHandleSerializer(
77 help_text="Reference to the VirtualCompute resource.",
80 storageResourceIds = serializers.ListSerializer(
81 help_text="References to the VirtualStorage resources. The value refers to a VirtualStorageResourceInfo item in the VnfInstance.",
82 child=serializers.CharField(help_text="Identifier In Vnf", allow_blank=True),
85 reservationId = serializers.CharField(
86 help_text="The reservation identifier applicable to the resource.",
91 vnfcCpInfo = VnfcCpInfo(
92 help_text="CPs of the VNFC instance. Shall be present when that particular CP of the VNFC instance is associated to an external CP of the VNF instance.",
96 metadata = serializers.DictField(
97 help_text="Metadata about this resource.",
101 # class VnfLinkPortInfo(serializers.Serializer):
102 # id = serializers.CharField(
103 # help_text="Identifier of this link port as provided by the entity that has created the link port.",
108 # resourceHandle = ResourceHandleSerializer(
109 # help_text="Reference to the virtualised network resource realizing this link port.",
112 # cpInstanceId = serializers.CharField(
113 # help_text="When the link port is used for external connectivity by the VNF, \
114 # this attribute represents the identifier of the external CP of the VNF to be connected to this link port.",
121 class VnfVirtualLinkResourceInfoSerializer(serializers.Serializer):
122 id = serializers.CharField(
123 help_text="Identifier of this VnfVirtualLinkResourceInfo instance.",
128 virtualLinkDescId = serializers.CharField(
129 help_text="Identifier of the VNF Virtual Link Descriptor (VLD) in the VNFD.",
134 networkResource = ResourceHandleSerializer(
135 help_text="Reference to the VirtualNetwork resource.",
138 reservationId = serializers.CharField(
139 help_text="The reservation identifier applicable to the resource.",
144 vnfLinkPorts = VnfLinkPortInfo(
145 help_text="Links ports of this VL. \
146 Shall be present when the linkPort is used for external connectivity by the VNF",
150 metadata = serializers.DictField(
151 help_text="Metadata about this resource.",
152 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
157 class VirtualStorageResourceInfoSerializer(serializers.Serializer):
158 id = serializers.CharField(
159 help_text="Identifier of this VirtualStorageResourceInfo instance.",
164 virtualStorageDescId = serializers.CharField(
165 help_text="Identifier of the VirtualStorageDesc in the VNFD.",
170 storageResource = ResourceHandleSerializer(
171 help_text="Reference to the VirtualStorage resource.",
174 reservationId = serializers.CharField(
175 help_text="The reservation identifier applicable to the resource.",
180 metadata = serializers.DictField(
181 help_text="Metadata about this resource.",
182 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
187 class InstantiatedVnfInfo(serializers.Serializer):
188 flavourId = serializers.CharField(
189 help_text="Identifier of the VNF deployment flavour applied to this VNF instance.",
194 vnfState = serializers.ChoiceField(
195 help_text="State of the VNF instance.",
196 choices=enum_to_list(VNF_STATE),
200 scaleStatus = VnfScaleInfoSerializer(
201 help_text="Scale status of the VNF, one entry per aspect. \
202 Represents for every scaling aspect how big the VNF has been scaled w.r.t. that aspect.",
206 extCpInfo = VnfExtCpInfoSerializer(
207 help_text="Information about the external CPs exposed by the VNF instance.",
211 extVirtualLinkInfo = ExtVirtualLinkInfoSerializer(
212 help_text="Information about the external VLs the VNF instance is connected to.",
216 extManagedVirtualLinkInfo = ExtManagedVirtualLinkInfo(
217 help_text="Information about the externally-managed inner VLs of the VNF instance.",
221 monitoringParameters = serializers.DictField(
222 help_text="Active monitoring parameters.",
223 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
226 localizationLanguage = serializers.CharField(
227 help_text="Information about localization language of the VNF.",
232 vnfcResourceInfo = VnfcResourceInfoSerializer(
233 help_text="Information about the virtualised compute and storage resources used by the VNFCs of the VNF instance.",
237 vnfVirtualLinkResourceInfo = VnfVirtualLinkResourceInfoSerializer(
238 help_text="Information about the virtualised network resources used by the VLs of the VNF instance.",
242 virtualStorageResourceInfo = VirtualStorageResourceInfoSerializer(
243 help_text="Information about the virtualised storage resources used as storage for the VNF instance.",
249 class VnfInstanceLinks(serializers.Serializer):
250 href = LinkSerializer(
251 help_text="URI of this resource.",
254 indicators = LinkSerializer(
255 help_text="Indicators related to this VNF instance.",
258 instantiate = LinkSerializer(
259 help_text="Link to the instantiate task resource.",
262 termiante = LinkSerializer(
263 help_text="Link to the terminate task resource.",
266 scale = LinkSerializer(
267 help_text="Link to the scale task resource.",
270 scaleToLevel = LinkSerializer(
271 help_text="Link to the scale_to_level task resource.",
274 changeFlavour = LinkSerializer(
275 help_text="Link to the change_flavour task resource.",
278 heal = LinkSerializer(
279 help_text="Link to the heal task resource.",
282 operate = LinkSerializer(
283 help_text="Link to the operate task resource.",
286 changeExtConn = LinkSerializer(
287 help_text="Link to the change_ext_conn task resource.",
292 class VnfInstanceSerializer(serializers.Serializer):
293 id = serializers.CharField(
294 help_text="Identifier of the VNF instance.",
299 vnfInstanceName = serializers.CharField(
300 help_text="Name of the VNF instance.",
305 vnfInstanceDescription = serializers.CharField(
306 help_text="Human-readable description of the VNF instance.",
310 vnfdId = serializers.CharField(
311 help_text="Identifier of the VNFD on which the VNF instance is based.",
316 vnfProvider = serializers.CharField(
317 help_text="Provider of the VNF and the VNFD.",
322 vnfProductName = serializers.CharField(
323 help_text="Name to identify the VNF Product.",
328 vnfSoftwareVersion = serializers.CharField(
329 help_text="Software version of the VNF.",
334 vnfdVersion = serializers.CharField(
335 help_text="Identifies the version of the VNFD.",
340 vnfPkgId = serializers.CharField(
341 help_text="Identifier of information held by the NFVO about the specific VNF package on which the VNF is based. \
342 This attribute can be modified with the PATCH method.",
347 vnfConfigurableProperties = serializers.DictField(
348 help_text="Current values of the configurable properties of the VNF instance. \
349 Configurable properties referred in this attribute are declared in the VNFD",
350 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
353 vimId = serializers.ListField(
354 help_text="Identifier set of a VIM that manages resources for the VNF instance.",
355 child=serializers.CharField(help_text="Identifier of a VIM that manages resources for the VNF instance.", allow_null=False),
357 instantiationState = serializers.ChoiceField(
358 help_text="The instantiation state of the VNF.",
359 choices=enum_to_list(INSTANTIATION_STATE),
363 instantiatedVnfInfo = InstantiatedVnfInfo(
364 help_text="Information specific to an instantiated VNF instance. \
365 This attribute shall be present if the instantiateState attribute value is INSTANTIATED",
368 metadata = serializers.DictField(
369 help_text="Additional VNF-specific metadata describing the VNF instance.\
370 This attribute can be modified with the PATCH method.",
371 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
374 extensions = serializers.DictField(
375 help_text="VNF-specific attributes that affect the lifecycle management of this VNF instance by the VNFM, or the lifecycle management scripts. \
376 This attribute can be modified with the PATCH method.",
377 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
380 _links = VnfInstanceLinks(
381 help_text="Links to resources related to this resource.",
386 class PnfExtCpInfoSerializer(serializers.Serializer):
387 cpInstanceId = serializers.CharField(
388 help_text="Identifier of the CP in the scope of the PNF.",
391 cpdId = serializers.CharField(
392 help_text="Identifier of (reference to) the Connection Point Descriptor (CPD) for this CP.",
395 cpProtocolData = CpProtocolDataSerializer(
396 help_text="Parameters for configuring the network protocols on the CP.",
401 class PnfInfoSerializer(serializers.Serializer):
402 pnfId = serializers.CharField(
403 help_text="Identifier of the PNF.",
405 pnfName = serializers.CharField(
406 help_text="Name of the PNF.",
408 pnfdId = serializers.CharField(
409 help_text="Identifier of the PNFD on which the PNF is based.",
411 pnfdInfoId = serializers.CharField(
412 help_text="Identifier of the PNFD information onject related to this PNF.",
414 pnfProfileId = serializers.CharField(
415 help_text="Identifier of the related PnfProfile in the NSD on which the PNF is based.",
417 cpInfo = PnfExtCpInfoSerializer(
418 help_text="Information on the external CP of the PNF",
423 class NsLinkPortInfo(serializers.Serializer):
424 id = serializers.CharField(
425 help_text="Identifier of this link port as provided by the entity that has created the link port.",
430 resourceHandle = ResourceHandleSerializer(
431 help_text="Reference to the virtualised resource realizing this link port.",
434 cpInstanceId = serializers.CharField(
435 help_text="Identifier of the external CP of the VNF connected to this link port. \
436 There shall be at most one link port associated with any external connection point instance.",
443 class NsVirtualLinkInfoSerializer(serializers.Serializer):
444 id = serializers.CharField(
445 help_text="Identifier of the VL instance.",
447 nsVirtualLinkDescId = serializers.CharField(
448 help_text="Identifier of the VLD in the NSD.",
450 nsVirtualLinkProfileId = serializers.CharField(
451 help_text="Identifier of the VL profile in the NSD.",
453 resourceHandle = ResourceHandleSerializer(
454 help_text="Identifier(s) of the virtualised network resource(s) realizing the VL instance",
457 linkPort = NsLinkPortInfo(
458 help_text="Link ports of this VL.",
464 class NsCpHandleSerializer(serializers.Serializer):
465 vnfInstanceId = serializers.CharField(
466 help_text="Identifier of the VNF instance associated to the CP instance.",
469 vnfExtCpInstanceId = serializers.CharField(
470 help_text="Identifier of the VNF external CP instance in the scope of the VNF instance.",
473 pnfInfoId = serializers.CharField(
474 help_text="Identifier of the PNF instance associated to the CP instance.",
477 pnfExtCpInstanceId = serializers.CharField(
478 help_text="Identifier of the PNF external CP instance in the scope of the PNF.",
481 nsInstanceId = serializers.CharField(
482 help_text="Identifier of the NS instance associated to the SAP instance",
485 nsSapInstanceId = serializers.CharField(
486 help_text="Identifier of the SAP instance in the scope of the NS instance.",
491 class MaskSerializer(serializers.Serializer):
492 startingPoint = serializers.CharField(
493 help_text="Indicates the offset between the last bit of the source mac address and the first bit of the sequence of bits to be matched.",
495 length = serializers.CharField(
496 help_text="Indicates the number of bits to be matched.",
498 value = serializers.CharField(
499 help_text="Provide the sequence of bit values to be matched.",
503 class NfpRuleSerializer(serializers.Serializer):
504 etherDestinationAddress = serializers.CharField(
505 help_text="Indicates a destination Mac address",
508 etherSourceAddress = serializers.CharField(
509 help_text="Indicates a source Mac address",
512 etherType = serializers.ChoiceField(
513 help_text="Indicates the protocol carried over the Ethernet layer",
514 choices=enum_to_list(IPADDRESSES_TYPE),
517 vlanTag = serializers.ListField(
518 help_text="ndicates a VLAN identifier in an IEEE 802.1Q-2014 tag",
521 protocol = serializers.ChoiceField(
522 help_text="Indicates the L4 protocol, For IPv4 [7] this corresponds to"
523 "the field called Protocol to identifythe next level protocol",
524 choices=enum_to_list(PROTOCOL),
527 dscp = serializers.CharField(
528 help_text="For IPv4 [7] a string of 0 and 1 digits that corresponds to the"
529 "6-bit Differentiated Services Code Point (DSCP) field of the IP header.",
532 sourcePortRange = serializers.CharField(
533 help_text="Indicates a range of source ports",
536 destinationPortRange = serializers.CharField(
537 help_text="Indicates a range of destination ports",
540 sourceIpAddressPrefix = serializers.CharField(
541 help_text="Indicates the source IP address range in CIDR format.",
544 destinationIpAddressPrefix = serializers.CharField(
545 help_text="Indicates the destination IP address range in CIDR format.",
548 extendedCriteria = MaskSerializer(
549 help_text="Indicates values of specific bits in a frame",
555 class NfpInfoSerializer(serializers.Serializer):
556 id = serializers.CharField(
557 help_text="Identifier of this NFP instance.",
559 nfpdId = serializers.CharField(
560 help_text="Identifier of the NFPD used to instantiate this NFP instance.",
563 nfpName = serializers.CharField(
564 help_text="Human readable name for the NFP instance.",
567 description = serializers.CharField(
568 help_text="Human readable description for the NFP instance.",
570 nscpHandle = NsCpHandleSerializer(
571 help_text="Identifier(s) of the CPs and/or SAPs which the NFP passes by",
574 totalCp = serializers.CharField(
575 help_text="Total number of CP and SAP instances in this NFP instance.",
578 nfpRule = NfpRuleSerializer(
579 help_text="The NfpRule data type is an expression of the conditions that shall be met in order for the NFP to be applicable to the packet",
581 nfpState = serializers.ChoiceField(
582 help_text="The state of the NFP instance.",
583 choices=enum_to_list(NFP_STATE),
587 class VnffgInfoSerializer(serializers.Serializer):
588 id = serializers.CharField(
589 help_text="Identifier of this VNFFG instance.",
591 vnffgdId = serializers.CharField(
592 help_text="Identifier of the VNFFGD in the NSD.",
594 vnfInstanceId = serializers.ListField(
595 help_text="Identifier(s) of the constituent VNF instance(s) of this VNFFG instance.",
596 child=serializers.CharField(
597 help_text="ID of vnf instance"),
599 pnfInfoId = serializers.ListField(
600 help_text="Identifier(s) of the constituent PNF instance(s) of this VNFFG instance",
601 child=serializers.CharField(help_text="ID of pnf info"),
604 nsVirtualLinkInfoId = serializers.ListField(
605 help_text="Identifier(s) of the constituent VL instance(s) of thisVNFFG instance.",
606 child=serializers.CharField(help_text="ID of ns virtual link info"),
608 nsCpHandle = NsCpHandleSerializer(
609 help_text="Identifiers of the CP instances attached to the "
610 "constituent VNFs and PNFs or the SAP instances of the VNFFG.",
614 nfpInfo = NfpInfoSerializer(
615 help_text="Information on the NFP instances.",
621 class SapInfo(serializers.Serializer):
622 id = serializers.CharField(
623 help_text="Identifier of the SAP instance.",
625 sapdId = serializers.CharField(
626 help_text="Reference to the SAPD for this SAP.",
628 sapName = serializers.CharField(
629 help_text="Human readable name for the SAP.",
631 description = serializers.CharField(
632 help_text="Human readable description for the SAP. ",
634 sapProtocolInfo = CpProtocolInfoSerializer(
635 help_text="Parameters for configuring the network protocols on the SAP.",
641 class NsLinkSerializer(serializers.Serializer):
642 self = LinkSerializer(
643 help_text="URI of this resource.",
645 nestedNsInstances = LinkSerializer(
646 help_text="Links to the nested NS instances of the present NS instance.",
649 instantiate = LinkSerializer(
650 help_text="Link to the instantiate task resource.",
653 terminate = LinkSerializer(
654 help_text="Link to the terminate task resource.",
657 update = LinkSerializer(
658 help_text="Link to the update task resource.",
661 scale = LinkSerializer(
662 help_text="Link to the scale task resource.",
665 heal = LinkSerializer(
666 help_text="Link to the heal task resource.",
671 class NsInstanceSerializer(serializers.Serializer):
672 id = serializers.CharField(
673 help_text="Identifier of the NS instance.",
675 nsInstanceName = serializers.CharField(
676 help_text="Human readable name of the NS instance.",
678 nsInstanceDescription = serializers.CharField(
679 help_text="Human readable description of the NS instance.",
681 nsdId = serializers.CharField(
682 help_text="Identifier of the NSD on which the NS instance is based.",
684 nsdInfoId = serializers.CharField(
685 help_text="Identifier of the NSD information object on which the NS instance is based.",
687 flavourId = serializers.CharField(
688 help_text="Identifier of the NS deployment flavour applied to the NS instance.",
690 vnfInstance = VnfInstanceSerializer(
691 help_text="Information on constituent VNF(s) of the NS instance.",
694 pnfInfo = PnfInfoSerializer(
695 help_text="Information on constituent PNF(s) of the NS instance.",
698 virtualLinkInfo = NsVirtualLinkInfoSerializer(
699 help_text="Information on the VL(s) of the NS instance.",
702 vnffgInfo = VnffgInfoSerializer(
705 help_text="VNF Forward Graph Information.")
709 help_text="Create data concerning the SAPs.")
710 nestedNsInstanceId = serializers.ListField(
711 help_text="Identifier of the nested NS(s) of the NS instance.",
712 child=serializers.CharField(),
715 nsState = serializers.ChoiceField(
716 help_text="The state of the NS instance.",
717 choices=enum_to_list(INSTANTIATION_STATE),
720 nsScaleStatus = NsScaleInfoSerializer(
721 help_text="Status of each NS scaling aspect declared in the applicable DF.",
725 additionalAffinityOrAntiAffinityRule = AffinityOrAntiAffinityRuleSerializer(
726 help_text="Specifies additional affinity or anti-affinity constraint for the VNF instances to be instantiated as part of the NS instantiation.",
730 _links = NsLinkSerializer(
731 help_text="The links of the NS instance.",