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