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 Links, ipAddressesSerializer, CpProtocolDataSerializer
18 from resource_handle import ResourceHandleSerializer
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 PnfExtCpInfoSerializer(serializers.Serializer):
42 cpInstanceId = serializers.CharField(help_text="Identifier of the CP in the scope of the PNF.",
45 cpdId = serializers.CharField(help_text="Identifier of (reference to) the Connection Point Descriptor"
46 "(CPD) for this CP.", required=True)
48 cpProtocolData = CpProtocolDataSerializer(help_text="Parameters for configuring the network protocols on"
49 "the CP.", required=True, many=True)
52 class PnfInfoSerializer(serializers.Serializer):
53 pnfId = serializers.CharField(help_text="Identifier of the PNF.", required=True)
54 pnfName = serializers.CharField(help_text="Name of the PNF.", required=True)
55 pnfdId = serializers.CharField(help_text="Identifier of the PNFD on which the PNF is based.",
58 pnfdInfoId = serializers.CharField(help_text="Identifier of the PNFD information onject related to this "
59 "PNF.", required=True)
60 pnfProfileId = serializers.CharField(help_text="Identifier of the related PnfProfile in the NSD on which "
61 "the PNF is based.", required=True)
63 cpInfo = PnfExtCpInfoSerializer(help_text="Information on the external CP of the PNF",
64 required=True, many=True)
67 # class ResourceHandleSerializer(serializers.Serializer):
68 # vimId = serializers.CharField(help_text="Identifier of the VIM under whose control this resource is"
69 # "placed.", required=False, allow_null=True)
70 # resourceProviderId = serializers.CharField(help_text="Identifier of the entity responsible for the"
71 # "management of the resource", required=False,
73 # resourceId = serializers.CharField(help_text="Identifier of the resource in the scope of the VIM or the "
74 # "resource provider.", required=True)
75 # vimLevelResourceType = serializers.CharField(help_text="Type of the resource in the scope of the VIM or"
76 # "the resource provider",
77 # required=False, allow_null=True)
80 class NsVirtualLinkInfoSerializer(serializers.Serializer):
81 id = serializers.CharField(help_text="Identifier of the VL instance.", required=True)
82 nsVirtualLinkDescId = serializers.CharField(help_text="Identifier of the VLD in the NSD.", required=True)
83 resourceHandle = ResourceHandleSerializer(help_text="Identifier(s) of the virtualised network resource(s)"
84 " realizing the VL instance",
85 required=True, many=True)
88 class NsCpHandleSerializer(serializers.Serializer):
89 vnfInstanceId = serializers.CharField(help_text="Identifier of the VNF instance associated to the CP"
90 "instance.", required=False, allow_null=True)
91 vnfExtCpInstanceId = serializers.CharField(help_text="Identifier of the VNF external CP instance in the"
92 "scope of the VNF instance.",
93 required=False, allow_null=True)
94 pnfInfoId = serializers.CharField(help_text="Identifier of the PNF instance associated to the CP"
95 "instance.", required=False, allow_null=True)
96 pnfExtCpInstanceId = serializers.CharField(help_text="Identifier of the PNF external CP instance in the"
97 "scope of the PNF.", required=False, allow_null=True)
98 nsInstanceId = serializers.CharField(help_text="Identifier of the NS instance associated to the SAP"
99 "instance", required=False, allow_null=True)
100 nsSapInstanceId = serializers.CharField(help_text="Identifier of the SAP instance in the scope of the NS"
101 "instance.", required=False, allow_null=True)
104 class MaskSerializer(serializers.Serializer):
105 startingPoint = serializers.CharField(help_text="Indicates the offset between the last bit of the source"
106 "mac address and the first bit of the sequence of bits"
107 "to be matched.", required=True)
108 length = serializers.CharField(help_text="Indicates the number of bits to be matched", required=True)
109 value = serializers.CharField(help_text="Provide the sequence of bit values to be matched.",
113 class NfpRuleSerializer(serializers.Serializer):
114 etherDestinationAddress = serializers.CharField(help_text="Indicates a destination Mac address",
115 required=False, allow_null=True)
116 etherSourceAddress = serializers.CharField(help_text="Indicates a source Mac address",
117 required=False, allow_null=True)
118 etherType = serializers.ChoiceField(help_text="Indicates the protocol carried over the Ethernet layer",
119 choices=["IPV4", "IPV6"], required=False, allow_null=True)
120 vlanTag = serializers.ListField(help_text="ndicates a VLAN identifier in an IEEE 802.1Q-2014 tag",
121 required=False, allow_null=True)
122 protocol = serializers.ChoiceField(help_text="Indicates the L4 protocol, For IPv4 [7] this corresponds to"
123 "the field called Protocol to identifythe next level "
124 "protocol", choices=["TCP", "UDP", "ICMP"],
125 required=False, allow_null=True)
126 dscp = serializers.CharField(help_text="For IPv4 [7] a string of 0 and 1 digits that corresponds to the"
127 "6-bit Differentiated Services Code Point (DSCP) field of the"
128 "IP header.", required=False, allow_null=True)
129 sourcePortRange = serializers.CharField(help_text="Indicates a range of source ports",
130 required=False, allow_null=True)
131 destinationPortRange = serializers.CharField(help_text="Indicates a range of destination ports",
132 required=False, allow_null=True)
133 sourceIpAddressPrefix = serializers.CharField(help_text="Indicates the source IP address range in CIDR"
134 "format.", required=False, allow_null=True)
135 destinationIpAddressPrefix = serializers.CharField(help_text="Indicates the destination IP address range"
137 required=False, allow_null=True)
138 extendedCriteria = MaskSerializer(help_text="Indicates values of specific bits in a frame",
139 required=False, allow_null=True, many=True)
142 class NfpInfoSerializer(serializers.Serializer):
143 id = serializers.CharField(help_text="Identifier of this NFP instance.", required=True)
144 nfpdId = serializers.CharField(help_text="Identifier of the NFPD used to instantiate this NFP"
145 "instance.", required=False, allow_null=True)
146 nfpName = serializers.CharField(help_text="Human readable name for the NFP instance.",
147 required=False, allow_null=True)
148 description = serializers.CharField(help_text="Human readable description for the NFP instance.",
150 nscpHandle = NsCpHandleSerializer(help_text="Identifier(s) of the CPs and/or SAPs which the NFP "
151 "passes by", required=True, many=True)
152 totalCp = serializers.CharField(help_text="Total number of CP and SAP instances in this NFP"
153 "instance.", required=False, allow_null=True)
154 nfpRule = NfpRuleSerializer(help_text="The NfpRule data type is an expression of the conditions that "
155 "shall be met in order for the NFP to be applicable to the packet",
157 nfpState = serializers.ChoiceField(help_text="The state of the NFP instance.",
158 choices=["ENABLED", "DISABLED"], required=True)
161 class VnffgInfoSerializer(serializers.Serializer):
162 id = serializers.CharField(help_text="Identifier of this VNFFG instance.", required=True)
163 vnffgdId = serializers.CharField(help_text="Identifier of the VNFFGD in the NSD.", required=True)
164 vnfInstanceId = serializers.ListField(help_text="Identifier(s) of the constituent VNF instance(s) of this"
166 child=serializers.CharField(help_text="ID of vnf instance"),
168 pnfInfoId = serializers.ListField(help_text="Identifier(s) of the constituent PNF instance(s) of this"
170 child=serializers.CharField(help_text="ID of pnf info"),
171 required=False, allow_null=True)
172 nsVirtualLinkInfoId = serializers.ListField(help_text="Identifier(s) of the constituent VL instance(s) of"
173 "thisVNFFG instance.",
174 child=serializers.CharField(
175 help_text="ID of ns virtual link info"), required=True)
176 nsCpHandle = NsCpHandleSerializer(help_text="Identifiers of the CP instances attached to the "
177 "constituent VNFs and PNFs or the SAP instances of "
178 "the VNFFG.", required=True, allow_null=False, many=True)
179 nfpInfo = NfpInfoSerializer(help_text="Information on the NFP instances.",
180 required=True, allow_null=False, many=True)
183 class IpOverEthernetAddressInfoSerializer(serializers.Serializer):
184 macAddress = serializers.CharField(help_text="Assigned MAC address", required=True)
185 ipAddresses = ipAddressesSerializer(help_text="Addresses assigned to the CP or SAP instance.",
186 required=False, allow_null=True, many=True)
189 class CpProtocolInfoSerializer(serializers.Serializer):
190 layerProtocol = serializers.ChoiceField(help_text="The identifier of layer(s) and protocol(s) associated"
191 "to the network address information.",
192 choices=["IP_OVER_ETHERNET"], required=True)
193 ipOverEthernet = IpOverEthernetAddressInfoSerializer(help_text="IP addresses over Ethernet to assign to"
194 "the CPor SAP instance.",
195 required=False, allow_null=True)
198 class SapInfoSerializer(serializers.Serializer):
199 id = serializers.CharField(help_text="Identifier of the SAP instance.", required=True)
200 sapdId = serializers.CharField(help_text="Identifier of the SAPD in the NSD.", required=True)
201 sapName = serializers.CharField(help_text="Human readable name for the SAP instance.", required=True)
202 description = serializers.CharField(help_text="Human readable description for the SAP instance.",
204 sapProtocolInfo = CpProtocolInfoSerializer(help_text="Network protocol information for this SAP.",
205 required=True, many=True)
208 class NsScaleInfoSerializer(serializers.Serializer):
209 nsScalingAspectId = serializers.CharField(help_text="Identifier of the NS scaling aspect.", required=True)
210 nsScaleLevelId = serializers.CharField(help_text="Identifier of the NS scale level.", required=True)
213 class AffinityOrAntiAffinityRuleSerializer(serializers.Serializer):
214 vnfdId = serializers.ListField(help_text="Reference to a VNFD.",
215 child=serializers.CharField(help_text="Identifier of the vnfd"),
216 required=False, allow_null=True)
217 vnfProfileId = serializers.ListField(help_text="Reference to a vnfProfile defined in the NSD.",
218 child=serializers.CharField(
219 help_text="Identifier of the vnfProfile"), required=True)
220 vnfInstanceId = serializers.ListField(help_text="Reference to the existing VNF instance as the subject of"
221 "the affinity or anti-affinity rule",
222 child=serializers.CharField(help_text="identifier of the"
224 required=False, allow_null=True)
225 affinityOrAntiAffiinty = serializers.ChoiceField(help_text="The type of the constraint.",
226 choices=["AFFINITY", "ANTI_AFFINITY"], required=True)
227 scope = serializers.ChoiceField(help_text="Specifies the scope of the rule where the placement"
228 "constraint applies.",
229 choices=["NFVI_POP", "ZONE", "ZONE_GROUP", "NFVI_NODE"], required=True)
232 class CreateNsRespSerializer(serializers.Serializer):
233 nsInstanceId = serializers.CharField(help_text="ID of NS instance", required=True)
234 nsInstanceName = serializers.CharField(help_text="Human readable name of the NS instance.", required=True)
235 nsInstanceDescription = serializers.CharField(help_text="Human readable description of the NS instance.",
237 nsdId = serializers.CharField(help_text="Identifier of the NSD on which the NS instance is based.",
239 nsdInfoId = serializers.CharField(help_text="Identifier of the NSD information object on which the "
240 "NS instance is based.", required=True)
241 flavourId = serializers.CharField(help_text="Identifier of the NS deployment flavour applied to "
242 "the NS instance.", required=False, allow_null=True)
243 vnfInstance = VnfInstanceSerializer(help_text="Information on constituent VNF(s) of the NS instance.",
244 required=False, allow_null=True, many=True)
246 pnfInfo = PnfInfoSerializer(help_text="Information on the PNF(s) that are part of the NS instance.",
247 required=False, allow_null=True, many=True)
248 virtualLinkInfo = NsVirtualLinkInfoSerializer(help_text="Information on the VL(s) of the NS instance.",
249 required=False, allow_null=True, many=True)
250 vnffgInfo = VnffgInfoSerializer(help_text="Information on the VNFFG(s) of the NS instance",
251 required=False, allow_null=True, many=True)
252 sapInfo = SapInfoSerializer(help_text="Information on the SAP(s) of the NS instance",
253 required=False, allow_null=True, many=True)
254 nestedNsInstanceId = serializers.ListField(help_text="Identifier of the nested NS(s) of the NS instance.",
255 child=serializers.CharField(help_text="nested of the NS"
257 required=False, allow_null=True)
258 nsState = serializers.ChoiceField(help_text="The state of the NS instance.", required=True,
259 choices=["NOT_INSTANTIATED", "INSTANTIATED"])
260 nsScaleStatus = NsScaleInfoSerializer(help_text="Status of each NS scaling aspect declared in the"
261 "applicable DF, how 'big' the NS instance has been"
262 "scaled w.r.t. that aspect.",
263 required=False, allow_null=True, many=True)
264 additionalAffinityOrAntiAffinityRule = AffinityOrAntiAffinityRuleSerializer(
265 help_text="Information on the additional affinity or anti-affinity rule from NS instantiation "
266 "operation.", required=False, allow_null=True, many=True)
267 _links = Links(help_text="Links to resources related to this resource.", required=True)