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