-
Notifications
You must be signed in to change notification settings - Fork 192
/
bgp.go
94 lines (72 loc) · 2.97 KB
/
bgp.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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package cli
import (
"context"
"time"
"github.com/spf13/cobra"
"github.com/cilium/cilium-cli/bgp"
"github.com/cilium/cilium-cli/defaults"
"github.com/cilium/cilium-cli/status"
)
func newCmdBgp() *cobra.Command {
cmd := &cobra.Command{
Use: "bgp",
Short: "Access to BGP control plane",
Long: ``,
}
cmd.AddCommand(newCmdBgpPeers())
cmd.AddCommand(newCmdBgpRoutes())
return cmd
}
func newCmdBgpPeers() *cobra.Command {
params := bgp.Parameters{}
cmd := &cobra.Command{
Use: "peers",
Aliases: []string{"neighbors"},
Short: "Lists BGP peering state",
Long: "This command lists the BGP state from all nodes in the cluster - requires cilium >= v1.13.2",
RunE: func(_ *cobra.Command, _ []string) error {
params.CiliumNamespace = namespace
s := bgp.NewStatus(k8sClient, params)
err := s.GetPeeringState(context.Background())
if err != nil {
fatalf("Unable to get peering status: %s", err)
}
return nil
},
}
cmd.Flags().StringVar(¶ms.AgentPodSelector, "agent-pod-selector", defaults.AgentPodSelector, "Label on cilium-agent pods to select with")
cmd.Flags().StringVar(¶ms.NodeName, "node", "", "Node from which BGP status will be fetched, omit to select all nodes")
cmd.Flags().DurationVar(¶ms.WaitDuration, "wait-duration", 1*time.Minute, "Maximum time to wait for result, default 1 minute")
cmd.Flags().StringVarP(¶ms.Output, "output", "o", status.OutputSummary, "Output format. One of: json, summary")
return cmd
}
func newCmdBgpRoutes() *cobra.Command {
params := bgp.Parameters{}
cmd := &cobra.Command{
Use: "routes <available | advertised> <afi> <safi> [vrouter <asn>] [peer|neighbor <address>]",
Short: "Lists BGP routes",
Long: "Lists BGP routes from all nodes in the cluster - requires cilium >= v1.14.6",
Example: ` Get all IPv4 unicast routes available:
cilium bgp routes available ipv4 unicast
Get all IPv6 unicast routes available for a specific vrouter:
cilium bgp routes available ipv6 unicast vrouter 65001
Get IPv4 unicast routes advertised to a specific peer:
cilium bgp routes advertised ipv4 unicast peer 10.0.0.1`,
RunE: func(_ *cobra.Command, args []string) error {
params.CiliumNamespace = namespace
s := bgp.NewStatus(k8sClient, params)
err := s.GetRoutes(context.Background(), args)
if err != nil {
fatalf("Unable to get BGP routes: %s", err)
}
return nil
},
}
cmd.Flags().StringVar(¶ms.AgentPodSelector, "agent-pod-selector", defaults.AgentPodSelector, "Label on cilium-agent pods to select with")
cmd.Flags().StringVar(¶ms.NodeName, "node", "", "Node from which BGP routes will be fetched, omit to select all nodes")
cmd.Flags().DurationVar(¶ms.WaitDuration, "wait-duration", 1*time.Minute, "Maximum time to wait for result, default 1 minute")
cmd.Flags().StringVarP(¶ms.Output, "output", "o", status.OutputSummary, "Output format. One of: json, summary")
return cmd
}