blob: 1be34f63cf5af0f7fec04287a6d8a8b44c7891a1 [file] [log] [blame]
Stephane Barbariea188d942018-10-16 16:43:04 -04001/*
2 * Copyright 2018-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 */
16package model
17
18import (
19 "github.com/opencord/voltha-go/common/log"
20 "github.com/opencord/voltha-go/protos/common"
21 "github.com/opencord/voltha-go/protos/openflow_13"
22 "github.com/opencord/voltha-go/protos/voltha"
23)
24
25type ModelTestConfig struct {
26 Root *root
27 Backend *Backend
28 RootProxy *Proxy
29 DbPrefix string
30 DbType string
31 DbHost string
32 DbPort int
33 DbTimeout int
34}
35
36var (
37 modelTestConfig = &ModelTestConfig{
38 DbPrefix: "service/voltha/data/core/0001",
39 DbType: "etcd",
40 DbHost: "localhost",
41 //DbHost: "10.106.153.44",
42 DbPort: 2379,
43 DbTimeout: 5,
44 }
45
46 ports = []*voltha.Port{
47 {
48 PortNo: 123,
49 Label: "test-port-0",
50 Type: voltha.Port_PON_OLT,
51 AdminState: common.AdminState_ENABLED,
52 OperStatus: common.OperStatus_ACTIVE,
53 DeviceId: "etcd_port-0-device-id",
54 Peers: []*voltha.Port_PeerPort{},
55 },
56 }
57
58 stats = &openflow_13.OfpFlowStats{
59 Id: 1111,
60 }
61 flows = &openflow_13.Flows{
62 Items: []*openflow_13.OfpFlowStats{stats},
63 }
64 device = &voltha.Device{
65 Id: devId,
66 Type: "simulated_olt",
67 Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"},
68 AdminState: voltha.AdminState_PREPROVISIONED,
69 Flows: flows,
70 Ports: ports,
71 }
72 devId string
73 targetDeviceId string
74)
75
76func init() {
77 log.AddPackage(log.JSON, log.WarnLevel, nil)
78 log.UpdateAllLoggers(log.Fields{"instanceId": "MODEL_TEST"})
79
80 defer log.CleanUp()
81
82 modelTestConfig.Backend = NewBackend(
83 modelTestConfig.DbType,
84 modelTestConfig.DbHost,
85 modelTestConfig.DbPort,
86 modelTestConfig.DbTimeout,
87 modelTestConfig.DbPrefix,
88 )
89
90 msgClass := &voltha.Voltha{}
91 root := NewRoot(msgClass, modelTestConfig.Backend)
92
93 if modelTestConfig.Backend != nil {
94 modelTestConfig.Root = root.Load(msgClass)
95 } else {
96 modelTestConfig.Root = root
97 }
98
99 GetProfiling().Report()
100
101 modelTestConfig.RootProxy = modelTestConfig.Root.GetProxy("/", false)
102}
103
104func commonCallback(args ...interface{}) interface{} {
105 log.Infof("Running common callback - arg count: %s", len(args))
106
107 for i := 0; i < len(args); i++ {
108 log.Infof("ARG %d : %+v", i, args[i])
109 }
110 execStatus := args[1].(*bool)
111
112 // Inform the caller that the callback was executed
113 *execStatus = true
114
115 return nil
116}
117
118func firstCallback(args ...interface{}) interface{} {
119 name := args[0]
120 id := args[1]
121 log.Infof("Running first callback - name: %s, id: %s\n", name, id)
122 return nil
123}
124func secondCallback(args ...interface{}) interface{} {
125 name := args[0].(map[string]string)
126 id := args[1]
127 log.Infof("Running second callback - name: %s, id: %f\n", name["name"], id)
128 // FIXME: the panic call seem to interfere with the logging mechanism
129 //panic("Generating a panic in second callback")
130 return nil
131}
132func thirdCallback(args ...interface{}) interface{} {
133 name := args[0]
134 id := args[1].(*voltha.Device)
135 log.Infof("Running third callback - name: %+v, id: %s\n", name, id.Id)
136 return nil
137}