blob: 51cc224880d8a894a5a029141db03bee6f0606f2 [file] [log] [blame]
Zack Williams41513bf2018-07-07 20:08:35 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Stephane Barbarie14088962017-06-01 16:56:55 -040016//package netconf-model
17package main
18
19/*
20#include <stdlib.h>
21#include <voltha-defs.h>
22*/
23import "C"
24
25import (
26 "log"
27 "encoding/xml"
28 "unsafe"
29)
30
31func init() {
32}
33
34// ----------------------------------------------
35// Data structures
36// ----------------------------------------------
37
38type Adapter struct {
39}
40
41type Adapters struct {
42 XMLName xml.Name `xml:"adapters"`
43 Items []Adapter
44}
45
46type LogicalDevice struct {
47}
48
49type LogicalDevices struct {
50 XMLName xml.Name `xml:"logical_devices"`
51 Items []LogicalDevice
52}
53
54type DeviceGroup struct {
55}
56
57type DeviceGroups struct {
58 XMLName xml.Name `xml:"device_groups"`
59 Items []Device
60}
61
62type DeviceType struct {
63}
64
65type DeviceTypes struct {
66 XMLName xml.Name `xml:"device_types"`
67 Items []DeviceType
68}
69
70type AlarmFilter struct {
71}
72
73type AlarmFilters struct {
74 XMLName xml.Name `xml:"alarm_filters"`
75 Items []AlarmFilter
76}
77
78type Custom struct {
79}
80
81type ProxyAddress struct {
82}
83
84type Port struct {
85}
86
87type Ports struct {
88 XMLName xml.Name `xml:"ports"`
89 Items []Port
90}
91
92type Flow struct {
93}
94
95type Flows struct {
96 XMLName xml.Name `xml:"flows"`
97 Items []Flow
98}
99
100type FlowGroup struct {
101}
102
103type FlowGroups struct {
104 XMLName xml.Name `xml:"flow_groups"`
105 Items []FlowGroup
106}
107
108type PmConfig struct {
109}
110
111type PmConfigs struct {
112 XMLName xml.Name `xml:"pm_configs"`
113 Items []PmConfig
114}
115
116type Address struct {
117 MacAddress string `xml:"mac_address,omitempty"`
118 Ipv4Address string `xml:"ipv4_address,omitempty"`
119 Ipv6Address string `xml:"ipv6_address,omitempty"`
120 HostAndPort string `xml:"host_and_port,omitempty"`
121}
122type Device struct {
123 XMLName xml.Name `xml:"device"`
124 Id string `xml:"id"`
125 Type string `xml:"type"`
126 Root int `xml:"root"`
127 ParentId string `xml:"parent_id"`
128 ParentPortNo int `xml:"parent_port_no"`
129 Vendor string `xml:"vendor"`
130 Model string `xml:"model"`
131 HardwareVersion string `xml:"hardware_version"`
132 FirmwareVersion string `xml:"firmware_version"`
133 SoftwareVersion string `xml:"software_version"`
134 Adapter string `xml:"adapter"`
135 Vlan int `xml:"vlan"`
136 ProxyAddress ProxyAddress `xml:"proxy_address"`
137 AdminState string `xml:"admin_state"`
138 OperStatus string `xml:"oper_status"`
139 Reason string `xml:"reason"`
140 ConnectStatus string `xml:"connect_status"`
141 Custom Custom `xml:"custom"`
142 Ports Ports `xml:"ports"`
143 Flows Flows `xml:"flows"`
144 FlowGroups FlowGroups `xml:"flow_groups"`
145 PmConfigs PmConfigs `xml:"pm_configs"`
146 Address
147}
148type Devices struct {
149 XMLName xml.Name `xml:"devices"`
150 Items []Device
151}
152
153type HealthStatus struct {
154 XMLName xml.Name `xml:"health"`
155 State string `xml:"state"`
156}
157type Voltha struct {
158 XMLName xml.Name `xml:"voltha"`
159 Version string `xml:"version"`
160 LogLevel string `xml:"log_level"`
161 Instances VolthaInstances `xml:"instances"`
162 Adapters Adapters `xml:"adapters"`
163 LogicalDevices LogicalDevices `xml:"logical_devices"`
164 Devices Devices `xml:"devices"`
165 DeviceGroups DeviceGroups `xml:"device_groups"`
166}
167type VolthaInstance struct {
168 XMLName xml.Name `xml:"voltha_instance"`
169 InstanceId string `xml:"instance_id"`
170 Version string `xml:"version"`
171 LogLevel string `xml:"log_level"`
172 HealthStatus string `xml:"health"`
173 Adapters Adapters `xml:"adapters"`
174 LogicalDevices LogicalDevices `xml:"logical_devices"`
175 Devices Devices `xml:"devices"`
176 DeviceTypes DeviceTypes `xml:"device_types"`
177 DeviceGroups DeviceGroups `xml:"device_groups"`
178 AlarmFilters AlarmFilters `xml:"alarm_filters"`
179}
180type VolthaInstances struct {
181 Items []VolthaInstance `xml:"items"`
182}
183
184// ----------------------------------------------
185// Conversion utility methods
186// ----------------------------------------------
187
188func _constructVolthaInstances(instances C.VolthaInstanceArray) VolthaInstances {
189 var v VolthaInstances
190 var item VolthaInstance
191 var c_instance C.VolthaInstance
192
193 length := instances.size
194 c_instances := (*[1 << 30]C.VolthaInstance)(unsafe.Pointer(instances.items))[:length:length]
195
196 for i := 0; i < int(instances.size); i += 1 {
197 c_instance = c_instances[i]
198 item.InstanceId = C.GoString(c_instance.InstanceId)
199 item.Version = C.GoString(c_instance.Version)
200 item.LogLevel = C.GoString(c_instance.LogLevel)
201 //item.HealthStatus = C.GoString(c_instance.Health)
202 item.Adapters = _constructAdapters(c_instance.Adapters)
203 item.LogicalDevices = _constructLogicalDevices(c_instance.LogicalDevices)
204 item.Devices = _constructDevices(c_instance.Devices)
205 item.DeviceTypes = _constructDeviceTypes(c_instance.DeviceTypes)
206 item.DeviceGroups = _constructDeviceGroups(c_instance.DeviceGroups)
207 item.AlarmFilters = _constructAlarmFilters(c_instance.AlarmFilters)
208
209 v.Items = append(v.Items, item)
210 }
211
212 return v
213}
214func _constructAdapters(instances C.AdapterArray) Adapters {
215 return Adapters{}
216}
217func _constructLogicalDevices(instances C.LogicalDeviceArray) LogicalDevices {
218 return LogicalDevices{}
219}
220func _constructDevices(instances C.DeviceArray) Devices {
221 var d Devices
222 var item Device
223 var c_instance C.Device
224
225 length := instances.size
226 log.Printf("number of instances : %d", length)
227 c_instances := (*[1 << 30]C.Device)(unsafe.Pointer(instances.items))[:length:length]
228
229 for i := 0; i < int(instances.size); i += 1 {
230 c_instance = c_instances[i]
231
232 item = _constructDevice(c_instance)
233
234 d.Items = append(d.Items, item)
235 }
236
237 return d
238}
239func _constructDeviceGroups(instances C.DeviceGroupArray) DeviceGroups {
240 return DeviceGroups{}
241}
242func _constructDeviceTypes(instances C.DeviceTypeArray) DeviceTypes {
243 return DeviceTypes{}
244}
245func _constructAlarmFilters(instances C.AlarmFilterArray) AlarmFilters {
246 return AlarmFilters{}
247}
248func _constructVoltha(voltha C.Voltha) Voltha {
249 return Voltha{
250 Version: C.GoString(voltha.Version),
251 LogLevel: C.GoString(voltha.LogLevel),
252 Instances: _constructVolthaInstances(voltha.Instances),
253 Adapters: _constructAdapters(voltha.Adapters),
254 LogicalDevices: _constructLogicalDevices(voltha.LogicalDevices),
255 Devices: _constructDevices(voltha.Devices),
256 DeviceGroups: _constructDeviceGroups(voltha.DeviceGroups),
257 }
258}
259func _constructProxyAddress(proxyAddress *C.Device_ProxyAddress) ProxyAddress {
260 return ProxyAddress{}
261}
262func _constructPorts(ports C.PortArray) Ports {
263 return Ports{}
264}
265func _constructFlows(flows *C.Flows) Flows {
266 return Flows{}
267}
268func _constructFlowGroups(flowGroups *C.FlowGroups) FlowGroups {
269 return FlowGroups{}
270}
271func _constructPmConfigs(pmConfigs *C.PmConfigs) PmConfigs {
272 return PmConfigs{}
273}
274func _constructAddress(address C.isDevice_Address) Address {
275 var a Address
276 switch address.Type {
277 case C.MAC:
278 a.MacAddress = C.GoString(address.Value)
279 case C.IPV4:
280 a.Ipv4Address = C.GoString(address.Value)
281 case C.IPV6:
282 a.Ipv6Address = C.GoString(address.Value)
283 case C.HOST_AND_PORT:
284 a.HostAndPort = C.GoString(address.Value)
285 }
286 return a
287}
288
289func _constructDevice(device C.Device) Device {
290 d := Device{
291 Id: C.GoString(device.Id),
292 Type: C.GoString(device.Type),
293 Root: int(device.Root),
294 ParentId: C.GoString(device.ParentId),
295 ParentPortNo: int(device.ParentPortNo),
296 Vendor: C.GoString(device.Vendor),
297 Model: C.GoString(device.Model),
298 HardwareVersion: C.GoString(device.HardwareVersion),
299 FirmwareVersion: C.GoString(device.FirmwareVersion),
300 SoftwareVersion: C.GoString(device.SoftwareVersion),
301 Adapter: C.GoString(device.Adapter),
302 Vlan: int(device.Vlan),
303 ProxyAddress: _constructProxyAddress(device.ProxyAddress),
304 AdminState: C.GoString(device.AdminState),
305 OperStatus: C.GoString(device.OperStatus),
306 Reason: C.GoString(device.Reason),
307 ConnectStatus: C.GoString(device.ConnectStatus),
308 Ports: _constructPorts(device.Ports),
309 Flows: _constructFlows(device.Flows),
310 FlowGroups: _constructFlowGroups(device.FlowGroups),
311 PmConfigs: _constructPmConfigs(device.PmConfigs),
312 Address: _constructAddress(device.Address),
313 }
314
315 return d
316}
317
318func _constructHealthStatus(health C.HealthStatus) HealthStatus {
319 return HealthStatus{
320 State: C.GoString(health.State),
321 }
322}
323
324// ----------------------------------------------
325// Exported translation methods
326// ----------------------------------------------
327
328//export TranslateVoltha
329func TranslateVoltha(voltha C.Voltha) *C.char {
330 var err error
331 var data []byte
332 var cs *C.char;
333 defer C.free(unsafe.Pointer(cs))
334
335 v := _constructVoltha(voltha)
336
337 if data, err = xml.Marshal(v); err != nil {
338 log.Printf("ERROR While marshalling: %s", err.Error())
339 }
340
341 cs = C.CString(string(data))
342
343 return cs
344}
345
346//export TranslateDevice
347func TranslateDevice(device C.Device) *C.char {
348 var err error
349 var data []byte
350 var cs *C.char;
351 defer C.free(unsafe.Pointer(cs))
352
353 d := _constructDevice(device)
354
355 if data, err = xml.Marshal(d); err != nil {
356 log.Printf("ERROR While marshalling: %s", err.Error())
357 }
358
359 cs = C.CString(string(data))
360
361 return cs
362}
363
364//export TranslateDevices
365func TranslateDevices(devices C.DeviceArray) *C.char {
366 var err error
367 var data []byte
368 var cs *C.char;
369 defer C.free(unsafe.Pointer(cs))
370
371 d := _constructDevices(devices)
372
373 if data, err = xml.Marshal(d); err != nil {
374 log.Printf("ERROR While marshalling: %s", err.Error())
375 }
376
377 cs = C.CString(string(data))
378
379 return cs
380}
381
382//export TranslateHealthStatus
383func TranslateHealthStatus(health C.HealthStatus) *C.char {
384 var err error
385 var data []byte
386 var cs *C.char;
387 defer C.free(unsafe.Pointer(cs))
388
389 d := _constructHealthStatus(health)
390
391 if data, err = xml.Marshal(d); err != nil {
392 log.Printf("ERROR While marshalling: %s", err.Error())
393 }
394
395 cs = C.CString(string(data))
396
397 return cs
398}
399
400func main() {
401 // We need the main function to make possible
402 // CGO compiler to compile the package as C shared library
403}