-
Notifications
You must be signed in to change notification settings - Fork 16
/
ovs_interface.go
197 lines (175 loc) · 6.24 KB
/
ovs_interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Copyright 2018 Paul Greenberg ([email protected])
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ovsdb
import (
"fmt"
//"github.com/davecgh/go-spew/spew"
)
// OvsInterface represents an OVS interface. The data help by the data
// structure is the same as the output of `ovs-vsctl list Interface`
// command.
//
// Reference: http://www.openvswitch.org/support/dist-docs/ovs-vswitchd.conf.db.5.html
type OvsInterface struct {
UUID string
Name string
Index float64 // reference from ovs-appctl dpif/show, e.g. OVN `tunnel_key`
BridgeName string // reference to datapath from ovs-appctl dpif/show
DatapathName string // reference to datapath from ovs-appctl dpif/show
AdminState string
Bfd map[string]string // TODO: unverified data type
BfdStatus map[string]string // TODO: unverified data type
CfmFault []string // TODO: unverified data type
CfmFaultStatus []string // TODO: unverified data type
CfmFlapCount []string // TODO: unverified data type
CfmHealth []string // TODO: unverified data type
CfmMpid []string // TODO: unverified data type
CfmRemoteMpids []string // TODO: unverified data type
CfmRemoteOpState []string // TODO: unverified data type
Duplex string
Error []string // TODO: unverified data type
ExternalIDs map[string]string
IfIndex float64
IngressPolicingBurst float64
IngressPolicingRate float64
LacpCurrent []string // TODO: unverified data type
LinkResets float64
LinkSpeed float64
LinkState string
Lldp map[string]string // TODO: unverified data type
Mac []string // TODO: unverified data type
MacInUse string // TODO: unverified data type
Mtu float64
MtuRequest []string // TODO: unverified data type
OfPort float64
OfPortRequest []string // TODO: unverified data type
Options map[string]string
OtherConfig map[string]string // TODO: unverified data type
Statistics map[string]int
Status map[string]string
Type string
}
// GetDbInterfaces returns a list of interfaces from the Interface table of OVS database.
func (cli *OvsClient) GetDbInterfaces() ([]*OvsInterface, error) {
intfs := []*OvsInterface{}
query := "SELECT * FROM Interface"
result, err := cli.Database.Vswitch.Client.Transact(cli.Database.Vswitch.Name, query)
if err != nil {
return intfs, fmt.Errorf("The '%s' query failed: %s", query, err)
}
if len(result.Rows) == 0 {
return intfs, fmt.Errorf("The '%s' query did not return any rows", query)
}
for _, row := range result.Rows {
intf := &OvsInterface{}
if r, dt, err := row.GetColumnValue("_uuid", result.Columns); err != nil {
continue
} else {
if dt != "string" {
continue
}
intf.UUID = r.(string)
}
if r, dt, err := row.GetColumnValue("name", result.Columns); err == nil {
if dt == "string" {
intf.Name = r.(string)
}
}
if r, dt, err := row.GetColumnValue("external_ids", result.Columns); err == nil {
if dt == "map[string]string" {
intf.ExternalIDs = r.(map[string]string)
}
} else {
intf.ExternalIDs = make(map[string]string)
}
if r, dt, err := row.GetColumnValue("ofport", result.Columns); err == nil {
if dt == "integer" {
intf.OfPort = float64(r.(int64))
}
}
if r, dt, err := row.GetColumnValue("ifindex", result.Columns); err == nil {
if dt == "integer" {
intf.IfIndex = float64(r.(int64))
}
}
if r, dt, err := row.GetColumnValue("mtu", result.Columns); err == nil {
if dt == "integer" {
intf.Mtu = float64(r.(int64))
}
}
if r, dt, err := row.GetColumnValue("mac_in_use", result.Columns); err == nil {
if dt == "string" {
intf.MacInUse = r.(string)
}
}
if r, dt, err := row.GetColumnValue("link_speed", result.Columns); err == nil {
if dt == "integer" {
intf.LinkSpeed = float64(r.(int64))
}
}
if r, dt, err := row.GetColumnValue("link_state", result.Columns); err == nil {
if dt == "string" {
intf.LinkState = r.(string)
}
}
if r, dt, err := row.GetColumnValue("admin_state", result.Columns); err == nil {
if dt == "string" {
intf.AdminState = r.(string)
}
}
if r, dt, err := row.GetColumnValue("ingress_policing_burst", result.Columns); err == nil {
if dt == "integer" {
intf.IngressPolicingBurst = float64(r.(int64))
}
}
if r, dt, err := row.GetColumnValue("ingress_policing_rate", result.Columns); err == nil {
if dt == "integer" {
intf.IngressPolicingRate = float64(r.(int64))
}
}
if r, dt, err := row.GetColumnValue("statistics", result.Columns); err == nil {
if dt == "map[string]integer" {
intf.Statistics = r.(map[string]int)
}
} else {
intf.Statistics = make(map[string]int)
}
if r, dt, err := row.GetColumnValue("status", result.Columns); err == nil {
if dt == "map[string]string" {
intf.Status = r.(map[string]string)
}
} else {
intf.Status = make(map[string]string)
}
if r, dt, err := row.GetColumnValue("options", result.Columns); err == nil {
if dt == "map[string]string" {
intf.Options = r.(map[string]string)
}
} else {
intf.Options = make(map[string]string)
}
if r, dt, err := row.GetColumnValue("type", result.Columns); err == nil {
if dt == "string" {
intf.Type = r.(string)
}
}
if r, dt, err := row.GetColumnValue("duplex", result.Columns); err == nil {
if dt == "string" {
intf.Duplex = r.(string)
}
}
intfs = append(intfs, intf)
}
return intfs, nil
}