-
Notifications
You must be signed in to change notification settings - Fork 17
/
l3.go
120 lines (104 loc) · 2.84 KB
/
l3.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
// -*- coding: utf-8 -*-
// Copyright (C) 2018 Nippon Telegraph and Telephone Corporation.
//
// 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 main
import (
"fmt"
api "gonsl/api"
log "github.com/sirupsen/logrus"
"golang.org/x/net/context"
)
func printL3Egress(l3egr *api.L3Egress) {
fmt.Printf("L3Egress: flags:%08x/%08x l3egrId:%d ifaceId:%d mac:%s vid:%d port:%d\n",
l3egr.GetFlags(),
l3egr.GetFlags2(),
l3egr.GetEgressId(),
l3egr.GetIfaceId(),
l3egr.GetMac(),
l3egr.GetVid(),
l3egr.GetPort(),
)
}
func dumpL3Egresses(client api.GoNSLApiClient) {
l3egrs, err := client.GetL3Egresses(context.Background(), api.NewGetL3EgressesRequest())
if err != nil {
log.Errorf("GetL3Egresses error. %s", err)
return
}
for _, l3egr := range l3egrs.Egresses {
printL3Egress(l3egr)
}
}
func printL3Host(l3host *api.L3Host) {
fmt.Printf("L3Host: Flags:%08x l3egrId:%d ip:%s ip6:%s mac:%s vrf:%d\n",
l3host.GetFlags(),
l3host.GetEgressId(),
l3host.GetIpAddr(),
l3host.GetIp6Addr(),
l3host.GetMac(),
l3host.GetVrf(),
)
}
func dumpL3Hosts(client api.GoNSLApiClient) {
l3hosts, err := client.GetL3Hosts(context.Background(), api.NewGetL3HostsRequest())
if err != nil {
log.Errorf("GetL3Hosts error. %s", err)
return
}
for _, l3host := range l3hosts.Hosts {
printL3Host(l3host)
}
}
func printL3Route(l3route *api.L3Route) {
fmt.Printf("L3Route: Flags:%08x l3egrId:%d ip:%s ip6:%s vrf:%d\n",
l3route.GetFlags(),
l3route.GetEgressId(),
l3route.GetIpAddr(),
l3route.GetIp6Addr(),
l3route.GetVrf(),
)
}
func dumpL3Routes(client api.GoNSLApiClient) {
l3routes, err := client.GetL3Routes(context.Background(), api.NewGetL3RoutesRequest())
if err != nil {
log.Errorf("GetL3Routes error. %s", err)
return
}
for _, l3route := range l3routes.Routes {
printL3Route(l3route)
}
}
func printL3Iface(iface *api.L3Iface) {
fmt.Printf("L3Iface: flags:%08x, ifaceId:%d mac:%s vid:%d vrf:%d mtu:%d:%d ttl:%d\n",
iface.GetFlags(),
iface.GetIfaceId(),
iface.GetMac(),
iface.GetVid(),
iface.GetVrf(),
iface.GetMtu(),
iface.GetMtuFwd(),
iface.GetTtl(),
)
}
func dumpL3Ifaces(client api.GoNSLApiClient) {
reply, err := client.GetL3Ifaces(context.Background(), api.NewGetL3IfacesRequest())
if err != nil {
log.Errorf("GetL3Iface error. %s", err)
return
}
for _, iface := range reply.Ifaces {
printL3Iface(iface)
}
}