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