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.const import IPADDRESSES_TYPE_LIST
27 INSTANTIATION_STATE = [
33 class VnfScaleInfoSerializer(serializers.Serializer):
34 aspectlId = serializers.Serializer(
35 help_text="Identifier of the scaling aspect",
37 scaleLevel = serializers.Serializer(
38 help_text="The scale level for that aspect.",
42 class NsScaleInfoSerializer(serializers.Serializer):
43 nsScalingAspectId = serializers.CharField(
44 help_text="Identifier of the NS scaling aspect.",
46 nsScaleLevelId = serializers.CharField(
47 help_text="Identifier of the NS scale level.",
51 class VnfcCpInfo(serializers.Serializer):
52 id = serializers.CharField(
53 help_text="Identifier of the external CP instance and the related information instance.",
55 cpdId = serializers.CharField(
56 help_text="Identifier of the external CPD, VnfExtCpd, in the VNFD.",
58 vnfExtCpId = serializers.CharField(
59 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.",
65 vnfLinkPortId = serializers.CharField(
66 help_text="Identifier of the vnfLinkPorts structure in the vnfVirtualLinkResourceInfo structure.",
70 class VnfcResourceInfoSerializer(serializers.Serializer):
71 id = serializers.CharField(
72 help_text="Identifier of this VnfcResourceInfo instance.",
76 vduId = serializers.CharField(
77 help_text="Reference to the applicable VDU in the VNFD.",
81 computeResource = ResourceHandleSerializer(
82 help_text="Reference to the VirtualCompute resource.",
85 storageResourceIds = serializers.ListSerializer(
86 help_text="References to the VirtualStorage resources. The value refers to a VirtualStorageResourceInfo item in the VnfInstance.",
87 child=serializers.CharField(help_text="Identifier In Vnf", allow_blank=True),
90 reservationId = serializers.CharField(
91 help_text="The reservation identifier applicable to the resource.",
96 vnfcCpInfo = VnfcCpInfo(
97 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.",
101 metadata = serializers.DictField(
102 help_text="Metadata about this resource.",
106 # class VnfLinkPortInfo(serializers.Serializer):
107 # id = serializers.CharField(
108 # help_text="Identifier of this link port as provided by the entity that has created the link port.",
113 # resourceHandle = ResourceHandleSerializer(
114 # help_text="Reference to the virtualised network resource realizing this link port.",
117 # cpInstanceId = serializers.CharField(
118 # help_text="When the link port is used for external connectivity by the VNF, \
119 # this attribute represents the identifier of the external CP of the VNF to be connected to this link port.",
126 class VnfVirtualLinkResourceInfoSerializer(serializers.Serializer):
127 id = serializers.CharField(
128 help_text="Identifier of this VnfVirtualLinkResourceInfo instance.",
133 virtualLinkDescId = serializers.CharField(
134 help_text="Identifier of the VNF Virtual Link Descriptor (VLD) in the VNFD.",
139 networkResource = ResourceHandleSerializer(
140 help_text="Reference to the VirtualNetwork resource.",
143 reservationId = serializers.CharField(
144 help_text="The reservation identifier applicable to the resource.",
149 vnfLinkPorts = VnfLinkPortInfo(
150 help_text="Links ports of this VL. \
151 Shall be present when the linkPort is used for external connectivity by the VNF",
155 metadata = serializers.DictField(
156 help_text="Metadata about this resource.",
157 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
162 class VirtualStorageResourceInfoSerializer(serializers.Serializer):
163 id = serializers.CharField(
164 help_text="Identifier of this VirtualStorageResourceInfo instance.",
169 virtualStorageDescId = serializers.CharField(
170 help_text="Identifier of the VirtualStorageDesc in the VNFD.",
175 storageResource = ResourceHandleSerializer(
176 help_text="Reference to the VirtualStorage resource.",
179 reservationId = serializers.CharField(
180 help_text="The reservation identifier applicable to the resource.",
185 metadata = serializers.DictField(
186 help_text="Metadata about this resource.",
187 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
192 class InstantiatedVnfInfo(serializers.Serializer):
193 flavourId = serializers.CharField(
194 help_text="Identifier of the VNF deployment flavour applied to this VNF instance.",
199 vnfState = serializers.ChoiceField(
200 help_text="State of the VNF instance.",
201 choices=["STARTED", "STOPPED"],
205 scaleStatus = VnfScaleInfoSerializer(
206 help_text="Scale status of the VNF, one entry per aspect. \
207 Represents for every scaling aspect how big the VNF has been scaled w.r.t. that aspect.",
211 extCpInfo = VnfExtCpInfoSerializer(
212 help_text="Information about the external CPs exposed by the VNF instance.",
216 extVirtualLinkInfo = ExtVirtualLinkInfoSerializer(
217 help_text="Information about the external VLs the VNF instance is connected to.",
221 extManagedVirtualLinkInfo = ExtManagedVirtualLinkInfo(
222 help_text="Information about the externally-managed inner VLs of the VNF instance.",
226 monitoringParameters = serializers.DictField(
227 help_text="Active monitoring parameters.",
228 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
231 localizationLanguage = serializers.CharField(
232 help_text="Information about localization language of the VNF.",
237 vnfcResourceInfo = VnfcResourceInfoSerializer(
238 help_text="Information about the virtualised compute and storage resources used by the VNFCs of the VNF instance.",
242 vnfVirtualLinkResourceInfo = VnfVirtualLinkResourceInfoSerializer(
243 help_text="Information about the virtualised network resources used by the VLs of the VNF instance.",
247 virtualStorageResourceInfo = VirtualStorageResourceInfoSerializer(
248 help_text="Information about the virtualised storage resources used as storage for the VNF instance.",
254 class VnfInstanceLinks(serializers.Serializer):
255 href = LinkSerializer(
256 help_text="URI of this resource.",
259 indicators = LinkSerializer(
260 help_text="Indicators related to this VNF instance.",
263 instantiate = LinkSerializer(
264 help_text="Link to the instantiate task resource.",
267 termiante = LinkSerializer(
268 help_text="Link to the terminate task resource.",
271 scale = LinkSerializer(
272 help_text="Link to the scale task resource.",
275 scaleToLevel = LinkSerializer(
276 help_text="Link to the scale_to_level task resource.",
279 changeFlavour = LinkSerializer(
280 help_text="Link to the change_flavour task resource.",
283 heal = LinkSerializer(
284 help_text="Link to the heal task resource.",
287 operate = LinkSerializer(
288 help_text="Link to the operate task resource.",
291 changeExtConn = LinkSerializer(
292 help_text="Link to the change_ext_conn task resource.",
297 class VnfInstanceSerializer(serializers.Serializer):
298 id = serializers.CharField(
299 help_text="Identifier of the VNF instance.",
304 vnfInstanceName = serializers.CharField(
305 help_text="Name of the VNF instance.",
310 vnfInstanceDescription = serializers.CharField(
311 help_text="Human-readable description of the VNF instance.",
315 vnfdId = serializers.CharField(
316 help_text="Identifier of the VNFD on which the VNF instance is based.",
321 vnfProvider = serializers.CharField(
322 help_text="Provider of the VNF and the VNFD.",
327 vnfProductName = serializers.CharField(
328 help_text="Name to identify the VNF Product.",
333 vnfSoftwareVersion = serializers.CharField(
334 help_text="Software version of the VNF.",
339 vnfdVersion = serializers.CharField(
340 help_text="Identifies the version of the VNFD.",
345 vnfPkgId = serializers.CharField(
346 help_text="Identifier of information held by the NFVO about the specific VNF package on which the VNF is based. \
347 This attribute can be modified with the PATCH method.",
352 vnfConfigurableProperties = serializers.DictField(
353 help_text="Current values of the configurable properties of the VNF instance. \
354 Configurable properties referred in this attribute are declared in the VNFD",
355 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
358 vimId = serializers.ListField(
359 help_text="Identifier set of a VIM that manages resources for the VNF instance.",
360 child=serializers.CharField(help_text="Identifier of a VIM that manages resources for the VNF instance.", allow_null=False),
362 instantiationState = serializers.ChoiceField(
363 help_text="The instantiation state of the VNF.",
364 choices=INSTANTIATION_STATE,
368 instantiatedVnfInfo = InstantiatedVnfInfo(
369 help_text="Information specific to an instantiated VNF instance. \
370 This attribute shall be present if the instantiateState attribute value is INSTANTIATED",
373 metadata = serializers.DictField(
374 help_text="Additional VNF-specific metadata describing the VNF instance.\
375 This attribute can be modified with the PATCH method.",
376 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
379 extensions = serializers.DictField(
380 help_text="VNF-specific attributes that affect the lifecycle management of this VNF instance by the VNFM, or the lifecycle management scripts. \
381 This attribute can be modified with the PATCH method.",
382 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
385 _links = VnfInstanceLinks(
386 help_text="Links to resources related to this resource.",
391 class PnfExtCpInfoSerializer(serializers.Serializer):
392 cpInstanceId = serializers.CharField(
393 help_text="Identifier of the CP in the scope of the PNF.",
396 cpdId = serializers.CharField(
397 help_text="Identifier of (reference to) the Connection Point Descriptor (CPD) for this CP.",
400 cpProtocolData = CpProtocolDataSerializer(
401 help_text="Parameters for configuring the network protocols on the CP.",
406 class PnfInfoSerializer(serializers.Serializer):
407 pnfId = serializers.CharField(
408 help_text="Identifier of the PNF.",
410 pnfName = serializers.CharField(
411 help_text="Name of the PNF.",
413 pnfdId = serializers.CharField(
414 help_text="Identifier of the PNFD on which the PNF is based.",
416 pnfdInfoId = serializers.CharField(
417 help_text="Identifier of the PNFD information onject related to this PNF.",
419 pnfProfileId = serializers.CharField(
420 help_text="Identifier of the related PnfProfile in the NSD on which the PNF is based.",
422 cpInfo = PnfExtCpInfoSerializer(
423 help_text="Information on the external CP of the PNF",
428 class NsLinkPortInfo(serializers.Serializer):
429 id = serializers.CharField(
430 help_text="Identifier of this link port as provided by the entity that has created the link port.",
435 resourceHandle = ResourceHandleSerializer(
436 help_text="Reference to the virtualised resource realizing this link port.",
439 cpInstanceId = serializers.CharField(
440 help_text="Identifier of the external CP of the VNF connected to this link port. \
441 There shall be at most one link port associated with any external connection point instance.",
448 class NsVirtualLinkInfoSerializer(serializers.Serializer):
449 id = serializers.CharField(
450 help_text="Identifier of the VL instance.",
452 nsVirtualLinkDescId = serializers.CharField(
453 help_text="Identifier of the VLD in the NSD.",
455 nsVirtualLinkProfileId = serializers.CharField(
456 help_text="Identifier of the VL profile in the NSD.",
458 resourceHandle = ResourceHandleSerializer(
459 help_text="Identifier(s) of the virtualised network resource(s) realizing the VL instance",
462 linkPort = NsLinkPortInfo(
463 help_text="Link ports of this VL.",
469 class NsCpHandleSerializer(serializers.Serializer):
470 vnfInstanceId = serializers.CharField(
471 help_text="Identifier of the VNF instance associated to the CP instance.",
474 vnfExtCpInstanceId = serializers.CharField(
475 help_text="Identifier of the VNF external CP instance in the scope of the VNF instance.",
478 pnfInfoId = serializers.CharField(
479 help_text="Identifier of the PNF instance associated to the CP instance.",
482 pnfExtCpInstanceId = serializers.CharField(
483 help_text="Identifier of the PNF external CP instance in the scope of the PNF.",
486 nsInstanceId = serializers.CharField(
487 help_text="Identifier of the NS instance associated to the SAP instance",
490 nsSapInstanceId = serializers.CharField(
491 help_text="Identifier of the SAP instance in the scope of the NS instance.",
496 class MaskSerializer(serializers.Serializer):
497 startingPoint = serializers.CharField(
498 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.",
500 length = serializers.CharField(
501 help_text="Indicates the number of bits to be matched.",
503 value = serializers.CharField(
504 help_text="Provide the sequence of bit values to be matched.",
508 class NfpRuleSerializer(serializers.Serializer):
509 etherDestinationAddress = serializers.CharField(
510 help_text="Indicates a destination Mac address",
513 etherSourceAddress = serializers.CharField(
514 help_text="Indicates a source Mac address",
517 etherType = serializers.ChoiceField(
518 help_text="Indicates the protocol carried over the Ethernet layer",
519 choices=IPADDRESSES_TYPE_LIST,
522 vlanTag = serializers.ListField(
523 help_text="ndicates a VLAN identifier in an IEEE 802.1Q-2014 tag",
526 protocol = serializers.ChoiceField(
527 help_text="Indicates the L4 protocol, For IPv4 [7] this corresponds to"
528 "the field called Protocol to identifythe next level protocol",
529 choices=["TCP", "UDP", "ICMP"],
532 dscp = serializers.CharField(
533 help_text="For IPv4 [7] a string of 0 and 1 digits that corresponds to the"
534 "6-bit Differentiated Services Code Point (DSCP) field of the IP header.",
537 sourcePortRange = serializers.CharField(
538 help_text="Indicates a range of source ports",
541 destinationPortRange = serializers.CharField(
542 help_text="Indicates a range of destination ports",
545 sourceIpAddressPrefix = serializers.CharField(
546 help_text="Indicates the source IP address range in CIDR format.",
549 destinationIpAddressPrefix = serializers.CharField(
550 help_text="Indicates the destination IP address range in CIDR format.",
553 extendedCriteria = MaskSerializer(
554 help_text="Indicates values of specific bits in a frame",
560 class NfpInfoSerializer(serializers.Serializer):
561 id = serializers.CharField(
562 help_text="Identifier of this NFP instance.",
564 nfpdId = serializers.CharField(
565 help_text="Identifier of the NFPD used to instantiate this NFP instance.",
568 nfpName = serializers.CharField(
569 help_text="Human readable name for the NFP instance.",
572 description = serializers.CharField(
573 help_text="Human readable description for the NFP instance.",
575 nscpHandle = NsCpHandleSerializer(
576 help_text="Identifier(s) of the CPs and/or SAPs which the NFP passes by",
579 totalCp = serializers.CharField(
580 help_text="Total number of CP and SAP instances in this NFP instance.",
583 nfpRule = NfpRuleSerializer(
584 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",
586 nfpState = serializers.ChoiceField(
587 help_text="The state of the NFP instance.",
588 choices=["ENABLED", "DISABLED"],
592 class VnffgInfoSerializer(serializers.Serializer):
593 id = serializers.CharField(
594 help_text="Identifier of this VNFFG instance.",
596 vnffgdId = serializers.CharField(
597 help_text="Identifier of the VNFFGD in the NSD.",
599 vnfInstanceId = serializers.ListField(
600 help_text="Identifier(s) of the constituent VNF instance(s) of this VNFFG instance.",
601 child=serializers.CharField(
602 help_text="ID of vnf instance"),
604 pnfInfoId = serializers.ListField(
605 help_text="Identifier(s) of the constituent PNF instance(s) of this VNFFG instance",
606 child=serializers.CharField(help_text="ID of pnf info"),
609 nsVirtualLinkInfoId = serializers.ListField(
610 help_text="Identifier(s) of the constituent VL instance(s) of thisVNFFG instance.",
611 child=serializers.CharField(help_text="ID of ns virtual link info"),
613 nsCpHandle = NsCpHandleSerializer(
614 help_text="Identifiers of the CP instances attached to the "
615 "constituent VNFs and PNFs or the SAP instances of the VNFFG.",
619 nfpInfo = NfpInfoSerializer(
620 help_text="Information on the NFP instances.",
626 class SapInfo(serializers.Serializer):
627 id = serializers.CharField(
628 help_text="Identifier of the SAP instance.",
630 sapdId = serializers.CharField(
631 help_text="Reference to the SAPD for this SAP.",
633 sapName = serializers.CharField(
634 help_text="Human readable name for the SAP.",
636 description = serializers.CharField(
637 help_text="Human readable description for the SAP. ",
639 sapProtocolInfo = CpProtocolInfoSerializer(
640 help_text="Parameters for configuring the network protocols on the SAP.",
646 class NsLinkSerializer(serializers.Serializer):
647 self = LinkSerializer(
648 help_text="URI of this resource.",
650 nestedNsInstances = LinkSerializer(
651 help_text="Links to the nested NS instances of the present NS instance.",
654 instantiate = LinkSerializer(
655 help_text="Link to the instantiate task resource.",
658 terminate = LinkSerializer(
659 help_text="Link to the terminate task resource.",
662 update = LinkSerializer(
663 help_text="Link to the update task resource.",
666 scale = LinkSerializer(
667 help_text="Link to the scale task resource.",
670 heal = LinkSerializer(
671 help_text="Link to the heal task resource.",
676 class NsInstanceSerializer(serializers.Serializer):
677 id = serializers.CharField(
678 help_text="Identifier of the NS instance.",
680 nsInstanceName = serializers.CharField(
681 help_text="Human readable name of the NS instance.",
683 nsInstanceDescription = serializers.CharField(
684 help_text="Human readable description of the NS instance.",
686 nsdId = serializers.CharField(
687 help_text="Identifier of the NSD on which the NS instance is based.",
689 nsdInfoId = serializers.CharField(
690 help_text="Identifier of the NSD information object on which the NS instance is based.",
692 flavourId = serializers.CharField(
693 help_text="Identifier of the NS deployment flavour applied to the NS instance.",
695 vnfInstance = VnfInstanceSerializer(
696 help_text="Information on constituent VNF(s) of the NS instance.",
699 pnfInfo = PnfInfoSerializer(
700 help_text="Information on constituent PNF(s) of the NS instance.",
703 virtualLinkInfo = NsVirtualLinkInfoSerializer(
704 help_text="Information on the VL(s) of the NS instance.",
707 vnffgInfo = VnffgInfoSerializer(
710 help_text="VNF Forward Graph Information.")
714 help_text="Create data concerning the SAPs.")
715 nestedNsInstanceId = serializers.ListField(
716 help_text="Identifier of the nested NS(s) of the NS instance.",
717 child=serializers.CharField(),
721 nsState = serializers.ChoiceField(
722 help_text="The state of the NS instance.",
723 choices=["NOT_INSTANTIATED", "INSTANTIATED"],
726 nsScaleStatus = NsScaleInfoSerializer(
727 help_text="Status of each NS scaling aspect declared in the applicable DF.",
731 additionalAffinityOrAntiAffinityRule = AffinityOrAntiAffinityRuleSerializer(
732 help_text="Specifies additional affinity or anti-affinity constraint for the VNF instances to be instantiated as part of the NS instantiation.",
736 _links = NsLinkSerializer(
737 help_text="The links of the NS instance.",