summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
authorWataru Ishida <ishida.wataru@lab.ntt.co.jp>2016-09-17 09:54:05 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-10-09 07:08:16 -0700
commitc3d8784efc24816e30c3ba68cad8f9a8d9d00b28 (patch)
tree5d2f9894e88b7631ffaa891795326e59310974e0 /packet
parente302689c60f603469110a8712b95b55544f4ce2d (diff)
packet/bgp: BGPCapabilityCode.String() pretty stringing
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r--packet/bgp/bgp.go19
-rw-r--r--packet/bgp/bgpcapabilitycode_string.go40
2 files changed, 19 insertions, 40 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index c45ccc81..916a5f69 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -216,6 +216,25 @@ const (
BGP_CAP_LONG_LIVED_GRACEFUL_RESTART BGPCapabilityCode = 129
)
+var CapNameMap = map[BGPCapabilityCode]string{
+ BGP_CAP_MULTIPROTOCOL: "multiprotocol",
+ BGP_CAP_ROUTE_REFRESH: "route-refresh",
+ BGP_CAP_CARRYING_LABEL_INFO: "carrying-label-info",
+ BGP_CAP_GRACEFUL_RESTART: "graceful-restart",
+ BGP_CAP_FOUR_OCTET_AS_NUMBER: "4-octet-as",
+ BGP_CAP_ADD_PATH: "add-path",
+ BGP_CAP_ENHANCED_ROUTE_REFRESH: "enhanced-route-refresh",
+ BGP_CAP_ROUTE_REFRESH_CISCO: "cisco-route-refresh",
+ BGP_CAP_LONG_LIVED_GRACEFUL_RESTART: "long-lived-graceful-restart",
+}
+
+func (c BGPCapabilityCode) String() string {
+ if n, y := CapNameMap[c]; y {
+ return n
+ }
+ return fmt.Sprintf("UnknownCapability(%d)", c)
+}
+
type ParameterCapabilityInterface interface {
DecodeFromBytes([]byte) error
Serialize() ([]byte, error)
diff --git a/packet/bgp/bgpcapabilitycode_string.go b/packet/bgp/bgpcapabilitycode_string.go
deleted file mode 100644
index 0dc70a87..00000000
--- a/packet/bgp/bgpcapabilitycode_string.go
+++ /dev/null
@@ -1,40 +0,0 @@
-// generated by stringer -type=BGPCapabilityCode; DO NOT EDIT
-
-package bgp
-
-import "fmt"
-
-const (
- _BGPCapabilityCode_name_0 = "BGP_CAP_MULTIPROTOCOLBGP_CAP_ROUTE_REFRESH"
- _BGPCapabilityCode_name_1 = "BGP_CAP_CARRYING_LABEL_INFO"
- _BGPCapabilityCode_name_2 = "BGP_CAP_GRACEFUL_RESTARTBGP_CAP_FOUR_OCTET_AS_NUMBER"
- _BGPCapabilityCode_name_3 = "BGP_CAP_ENHANCED_ROUTE_REFRESH"
- _BGPCapabilityCode_name_4 = "BGP_CAP_ROUTE_REFRESH_CISCO"
-)
-
-var (
- _BGPCapabilityCode_index_0 = [...]uint8{0, 21, 42}
- _BGPCapabilityCode_index_1 = [...]uint8{0, 27}
- _BGPCapabilityCode_index_2 = [...]uint8{0, 24, 52}
- _BGPCapabilityCode_index_3 = [...]uint8{0, 30}
- _BGPCapabilityCode_index_4 = [...]uint8{0, 27}
-)
-
-func (i BGPCapabilityCode) String() string {
- switch {
- case 1 <= i && i <= 2:
- i -= 1
- return _BGPCapabilityCode_name_0[_BGPCapabilityCode_index_0[i]:_BGPCapabilityCode_index_0[i+1]]
- case i == 4:
- return _BGPCapabilityCode_name_1
- case 64 <= i && i <= 65:
- i -= 64
- return _BGPCapabilityCode_name_2[_BGPCapabilityCode_index_2[i]:_BGPCapabilityCode_index_2[i+1]]
- case i == 70:
- return _BGPCapabilityCode_name_3
- case i == 128:
- return _BGPCapabilityCode_name_4
- default:
- return fmt.Sprintf("BGPCapabilityCode(%d)", i)
- }
-}