blob: 4126ee29e8183fff33e706118ecc61b162f65284 [file] [log] [blame]
Takahiro Suzukid7bf8202020-12-17 20:21:59 +09001/*
2 * Copyright 2020-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 */
Kengof20xx05d74022020-12-21 11:56:38 +090016
Takahiro Suzukid7bf8202020-12-17 20:21:59 +090017package core
18
19import (
20 "context"
21 "encoding/json"
22 "fmt"
23 "io/ioutil"
24 "os"
25 "time"
26)
27
28type AddFlowParam struct {
29 Value1 string `json:"value1"`
30 Value2 string `json:"value2"`
31 Value3 string `json:"value3"`
32}
33type AddFlowDownParam struct {
34 Value1 string `json:"value1"`
35 Value2 string `json:"value2"`
36 Value3 string `json:"value3"`
37}
38type AddFlowUpParam struct {
39 Value1 string `json:"value1"`
40 Value2 string `json:"value2"`
41 Value3 string `json:"value3"`
42}
43
44type OltCtlJson struct {
45 Command string `json:"command"`
46 Command_help []string `json:"command_help"`
47 AddFlowParam AddFlowParam `json:"addFlowParam"`
48 AddFlowDownParam AddFlowDownParam `json:"addFlowDownParam"`
49 AddFlowUpParam AddFlowUpParam `json:"addFlowUpParam"`
50}
51
52func init() {
53}
54
55func oltctl_main() {
56 for {
57 time.Sleep(1 * time.Second)
58 jsonData := readJson()
59 if jsonData == nil {
60 continue
61 }
62
63 switch jsonData.Command {
64 case "AddFlow":
65 oltctl_AddFlow(&jsonData.AddFlowParam)
66 case "AddFlowDown":
67 oltctl_AddFlowDown(&jsonData.AddFlowDownParam)
68 case "AddFlowUp":
69 oltctl_AddFlowUp(&jsonData.AddFlowUpParam)
70 default:
71
72 }
73 jsonData.Command = "None"
74 writeJson(jsonData)
75
76 }
77
78}
79func oltctl_AddFlow(param *AddFlowParam) {
80 logger.Debug(context.Background(), fmt.Sprintf("oltctl_AddFlow() %v", param))
81}
82func oltctl_AddFlowDown(param *AddFlowDownParam) {
83 logger.Debug(context.Background(), fmt.Sprintf("oltctl_AddFlowDown() %v", param))
84}
85func oltctl_AddFlowUp(param *AddFlowUpParam) {
86 logger.Debug(context.Background(), fmt.Sprintf("oltctl_AddFlowUp() %v", param))
87}
88
89func readJson() *OltCtlJson {
90 bytes, err := ioutil.ReadFile(os.Getenv("HOME") + "/oltctl.json")
91 if err != nil {
92 fmt.Printf("json read error. %v\n", err)
93 return nil
94 }
95 jsonData := &OltCtlJson{}
96 if err := json.Unmarshal(bytes, jsonData); err != nil {
97 fmt.Printf("json unmarshal error. %v\n", err)
98 return nil
99 }
100 return jsonData
101}
102func writeJson(jsonData *OltCtlJson) {
103
104 bytes, err := json.Marshal(jsonData)
105 if err != nil {
106 return
107 }
108 ioutil.WriteFile(os.Getenv("HOME")+"/oltctl.json", bytes, 0644)
109}