blob: 26edce6710c802f7a68ee9013ee3ce9f9de97006 [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"
Stephane Barbariedc5022d2018-11-19 15:21:44 -050023 "sync"
Stephane Barbariea188d942018-10-16 16:43:04 -040024)
25
26type ModelTestConfig struct {
27 Root *root
28 Backend *Backend
29 RootProxy *Proxy
30 DbPrefix string
31 DbType string
32 DbHost string
33 DbPort int
34 DbTimeout int
35}
36
37var (
38 modelTestConfig = &ModelTestConfig{
Stephane Barbarie1ab43272018-12-08 21:42:13 -050039 DbPrefix: "service/voltha",
Stephane Barbariedc5022d2018-11-19 15:21:44 -050040 DbType: "etcd",
41 DbHost: "localhost",
Stephane Barbariea188d942018-10-16 16:43:04 -040042 //DbHost: "10.106.153.44",
43 DbPort: 2379,
44 DbTimeout: 5,
45 }
46
Stephane Barbariedc5022d2018-11-19 15:21:44 -050047 logports = []*voltha.LogicalPort{
48 {
49 Id: "123",
50 DeviceId: "logicalport-0-device-id",
51 DevicePortNo: 123,
52 RootPort: false,
53 },
54 }
Stephane Barbariea188d942018-10-16 16:43:04 -040055 ports = []*voltha.Port{
56 {
57 PortNo: 123,
58 Label: "test-port-0",
59 Type: voltha.Port_PON_OLT,
60 AdminState: common.AdminState_ENABLED,
61 OperStatus: common.OperStatus_ACTIVE,
62 DeviceId: "etcd_port-0-device-id",
63 Peers: []*voltha.Port_PeerPort{},
64 },
65 }
66
67 stats = &openflow_13.OfpFlowStats{
68 Id: 1111,
69 }
70 flows = &openflow_13.Flows{
71 Items: []*openflow_13.OfpFlowStats{stats},
72 }
73 device = &voltha.Device{
Stephane Barbariedc5022d2018-11-19 15:21:44 -050074 Id: devID,
Stephane Barbariea188d942018-10-16 16:43:04 -040075 Type: "simulated_olt",
76 Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"},
77 AdminState: voltha.AdminState_PREPROVISIONED,
78 Flows: flows,
79 Ports: ports,
80 }
Stephane Barbariedc5022d2018-11-19 15:21:44 -050081
82 logicalDevice = &voltha.LogicalDevice{
83 Id: devID,
84 DatapathId: 0,
85 Ports: logports,
86 Flows: flows,
87 }
88
89 devID string
90 ldevID string
91 targetDevID string
92 targetLogDevID string
Stephane Barbariea188d942018-10-16 16:43:04 -040093)
94
95func init() {
96 log.AddPackage(log.JSON, log.WarnLevel, nil)
97 log.UpdateAllLoggers(log.Fields{"instanceId": "MODEL_TEST"})
98
99 defer log.CleanUp()
100
101 modelTestConfig.Backend = NewBackend(
102 modelTestConfig.DbType,
103 modelTestConfig.DbHost,
104 modelTestConfig.DbPort,
105 modelTestConfig.DbTimeout,
106 modelTestConfig.DbPrefix,
107 )
108
109 msgClass := &voltha.Voltha{}
110 root := NewRoot(msgClass, modelTestConfig.Backend)
Stephane Barbariedc5022d2018-11-19 15:21:44 -0500111 //root := NewRoot(msgClass, nil)
Stephane Barbariea188d942018-10-16 16:43:04 -0400112
Stephane Barbarie1ab43272018-12-08 21:42:13 -0500113 //if modelTestConfig.Backend != nil {
114 //modelTestConfig.Root = root.Load(msgClass)
115 //} else {
116 modelTestConfig.Root = root
117 //}
Stephane Barbariea188d942018-10-16 16:43:04 -0400118
119 GetProfiling().Report()
120
Stephane Barbariedc5022d2018-11-19 15:21:44 -0500121 modelTestConfig.RootProxy = modelTestConfig.Root.node.CreateProxy("/", false)
Stephane Barbariea188d942018-10-16 16:43:04 -0400122}
123
124func commonCallback(args ...interface{}) interface{} {
125 log.Infof("Running common callback - arg count: %s", len(args))
126
127 for i := 0; i < len(args); i++ {
128 log.Infof("ARG %d : %+v", i, args[i])
129 }
Stephane Barbariedc5022d2018-11-19 15:21:44 -0500130
131 mutex := sync.Mutex{}
Stephane Barbariea188d942018-10-16 16:43:04 -0400132 execStatus := args[1].(*bool)
133
134 // Inform the caller that the callback was executed
Stephane Barbariedc5022d2018-11-19 15:21:44 -0500135 mutex.Lock()
Stephane Barbariea188d942018-10-16 16:43:04 -0400136 *execStatus = true
Stephane Barbariedc5022d2018-11-19 15:21:44 -0500137 mutex.Unlock()
138
139 return nil
140}
141
142func commonCallback2(args ...interface{}) interface{} {
143 log.Infof("Running common callback - arg count: %s", len(args))
144
145 return nil
146}
147
148func commonCallbackFunc(args ...interface{}) interface{} {
149 log.Infof("Running common callback - arg count: %d", len(args))
150
151 for i := 0; i < len(args); i++ {
152 log.Infof("ARG %d : %+v", i, args[i])
153 }
154 execStatusFunc := args[1].(func(bool))
155
156 // Inform the caller that the callback was executed
157 execStatusFunc(true)
Stephane Barbariea188d942018-10-16 16:43:04 -0400158
159 return nil
160}
161
162func firstCallback(args ...interface{}) interface{} {
163 name := args[0]
164 id := args[1]
165 log.Infof("Running first callback - name: %s, id: %s\n", name, id)
166 return nil
167}
Stephane Barbariedc5022d2018-11-19 15:21:44 -0500168
Stephane Barbariea188d942018-10-16 16:43:04 -0400169func secondCallback(args ...interface{}) interface{} {
170 name := args[0].(map[string]string)
171 id := args[1]
172 log.Infof("Running second callback - name: %s, id: %f\n", name["name"], id)
173 // FIXME: the panic call seem to interfere with the logging mechanism
174 //panic("Generating a panic in second callback")
175 return nil
176}
Stephane Barbariedc5022d2018-11-19 15:21:44 -0500177
Stephane Barbariea188d942018-10-16 16:43:04 -0400178func thirdCallback(args ...interface{}) interface{} {
179 name := args[0]
180 id := args[1].(*voltha.Device)
181 log.Infof("Running third callback - name: %+v, id: %s\n", name, id.Id)
182 return nil
183}