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