blob: 88627651ad34c4d092f13fffee73c026b682c57f [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301/*
2* Copyright 2022-present Open Networking Foundation
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.
vinokuma926cb3e2023-03-29 11:41:06 +053014 */
Naveen Sampath04696f72022-06-13 15:19:14 +053015package main
16
17/*
18import (
19 "bufio"
20 "fmt"
21 "os"
22 "regexp"
23 "strconv"
24 "strings"
25
26 app "voltha-go-controller/internal/pkg/application"
27 "voltha-go-controller/internal/pkg/of"
28)
29
30// ProcessAddSub to add sub info
31func ProcessAddSub(tokens []string) {
32 device := "OpenOLT100"
33 port := uint32(100)
34 cvlan := uint16(100)
35 uvlan := uint16(4096)
36 svlan := uint16(4096)
37 for _, token := range tokens {
38 s := strings.Split(token, "=")
39 switch s[0] {
40 case "device":
41 device = s[1]
42 case "port":
43 res, _ := strconv.Atoi(s[1])
44 port = uint32(res)
45 case "cvlan":
46 res, _ := strconv.Atoi(s[1])
47 cvlan = uint16(res)
48 case "uvlan":
49 res, _ := strconv.Atoi(s[1])
50 uvlan = uint16(res)
51 case "svlan":
52 res, _ := strconv.Atoi(s[1])
53 svlan = uint16(res)
54 }
55 }
56 portStr := "OFPort" + strconv.FormatInt(int64(port), 10)
57 var vsc app.VoltServiceCfg
58 vsc.UniVlan = of.VlanType(uvlan)
59 vsc.CVlan = of.VlanType(cvlan)
60 vsc.SVlan = of.VlanType(svlan)
61 vsc.CircuitID = device + portStr
62 vsc.RemoteID = []byte("test")
63 vsc.Port = portStr
64 vsc.Name = device + portStr + strconv.FormatInt(int64(cvlan), 10)
65
66 app.GetApplication().AddService(vsc, nil)
67}
68
69// ProcessAddSubs to add multiple sub info
70func ProcessAddSubs(tokens []string) {
71 device := "OpenOLT100"
72 cvlan := uint16(1015)
73 uvlan := uint16(1015)
74 svlan := uint16(2)
75 //maclearning := false
76 numSubs, _ := strconv.Atoi(tokens[0])
77 for _, token := range tokens[1:] {
78 s := strings.Split(token, "=")
79 switch s[0] {
80 case "device":
81 device = s[1]
82 case "cvlan":
83 res, _ := strconv.Atoi(s[1])
84 cvlan = uint16(res)
85 case "uvlan":
86 res, _ := strconv.Atoi(s[1])
87 uvlan = uint16(res)
88 case "svlan":
89 res, _ := strconv.Atoi(s[1])
90 svlan = uint16(res)
91 // case "maclearning":
92 // maclearning = true
93 }
94 }
95 fmt.Println("Adding", numSubs, "Subscribers")
96 for port := 1; port <= numSubs; port++ {
97 for pbit := 0; pbit < 2; pbit++ {
98 p := of.PbitType(pbit)
99 portStr := "OFPort" + strconv.FormatInt(int64(port), 10)
100 var vsc app.VoltServiceCfg
101 vsc.UniVlan = of.VlanType(uvlan)
102 vsc.CVlan = of.VlanType(cvlan)
103 vsc.SVlan = of.VlanType(svlan)
104 vsc.Pbits = []of.PbitType{p, p + 2, p + 4, p + 6}
105 vsc.CircuitID = device + portStr
106 // TODO : need to fix this only if its used.
107 //vsc.MacLearning = maclearning
108 vsc.RemoteID = []byte("test")
109 vsc.Port = portStr
110 vsc.Name = portStr + strconv.FormatInt(int64(cvlan), 10) + "PBIT" + strconv.FormatInt(int64(pbit), 10)
111
112 if err := app.GetApplication().AddService(vsc, nil); err != nil {
113 fmt.Println("Addition of sub with", port, "Pbit", pbit, "Failed - Reason", err.Error())
114 }
115 }
116 }
117}
118
119// ProcessAddVnet to add vnet info
120func ProcessAddVnet(tokens []string) {
121 // Set the defaults so that each parameter doesn't need to be
122 // configured each time
123 cvlan := of.VlanType(1015)
124 svlan := of.VlanType(2)
125 uvlan := of.VlanType(1015)
126 dhcprelay := false
127 usdhcppbit := uint8(0)
128 dsdhcppbit := uint8(6)
129
130 // Read the attributes and set the values
131 for _, token := range tokens[:] {
132 s := strings.Split(token, "=")
133 switch s[0] {
134 case "dhcprelay":
135 dhcprelay = true
136 case "cvlan":
137 res, _ := strconv.Atoi(s[1])
138 cvlan = of.VlanType(res)
139 case "uvlan":
140 res, _ := strconv.Atoi(s[1])
141 uvlan = of.VlanType(res)
142 case "svlan":
143 res, _ := strconv.Atoi(s[1])
144 svlan = of.VlanType(res)
145 case "usdhcppbit":
146 res, _ := strconv.Atoi(s[1])
147 usdhcppbit = uint8(res)
148 case "dsdhcppbit":
149 res, _ := strconv.Atoi(s[1])
150 usdhcppbit = uint8(res)
151 }
152 }
153
154 // Perform the configuration
155 name := "NW" + strconv.FormatInt(int64(svlan), 10) + "-" + strconv.FormatInt(int64(cvlan), 10)
156 cfg := app.VnetConfig{
157 Name: name,
158 SVlan: svlan,
159 CVlan: cvlan,
160 UniVlan: uvlan,
161 DhcpRelay: dhcprelay,
162 }
163 cfg.UsDhcpPbit = append(cfg.UsDhcpPbit, of.PbitType(usdhcppbit))
164 cfg.DsDhcpPbit = append(cfg.DsDhcpPbit, of.PbitType(dsdhcppbit))
165 if err := app.GetApplication().AddVnet(cfg, nil); err != nil {
166 fmt.Println("Error in configuration - Reason :", err.Error())
167 }
168}
169
170// ProcessDelSubs to delete multiple sub info
171func ProcessDelSubs(tokens []string) {
172 cvlan := uint16(1015)
173 numSubs, _ := strconv.Atoi(tokens[0])
174 for _, token := range tokens[1:] {
175 s := strings.Split(token, "=")
176 switch s[0] {
177 // case "device":
178 // device = s[1]
179 case "cvlan":
180 res, _ := strconv.Atoi(s[1])
181 cvlan = uint16(res)
182 // case "uvlan":
183 // res, _ := strconv.Atoi(s[1])
184 // uvlan = uint16(res)
185 // case "svlan":
186 // res, _ := strconv.Atoi(s[1])
187 // svlan = uint16(res)
188 // case "maclearning":
189 // maclearning = true
190 }
191 }
192 fmt.Println("Deleting", numSubs, "Subscribers")
193 for port := 1; port <= numSubs; port++ {
194 for pbit := 0; pbit < 2; pbit++ {
195 portStr := "OFPort" + strconv.FormatInt(int64(port), 10)
196 name := portStr + strconv.FormatInt(int64(cvlan), 10) + "PBIT" + strconv.FormatInt(int64(pbit), 10)
197 app.GetApplication().DelService(name, false, nil, false)
198 }
199 }
200}
201
202// ProcessCli to process cli
203func ProcessCli() {
204 scanner := bufio.NewScanner(os.Stdin)
205 a := regexp.MustCompile(" +")
206 for {
207 fmt.Print("Controller> Enter Command:")
208 scanner.Scan()
209 command := scanner.Text()
210 s := a.Split(command, -1)
211 switch s[0] {
212 case "addsub":
213 ProcessAddSub(s[1:])
214 case "addsubs":
215 ProcessAddSubs(s[1:])
216 case "delsubs":
217 ProcessDelSubs(s[1:])
218 case "addvnet":
219 ProcessAddVnet(s[1:])
220 case "exit":
221 return
222 case "":
223
224 default:
225 fmt.Println("Unknown Command")
226 }
227 }
228}*/