diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-02-29 16:53:01 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-02-29 16:53:01 -0800 |
commit | d6998affcf413291fd615c88df958ea85baf481e (patch) | |
tree | 9c4246ed0f2325f6589abc3a5399ea69cb804f0d | |
parent | 1f6e2d490b6dc354197d33c187e24842c9673396 (diff) |
cli: delete duplicated code
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | gobgp/cmd/common.go | 14 | ||||
-rw-r--r-- | gobgp/cmd/global.go | 2 | ||||
-rw-r--r-- | table/path.go | 14 |
3 files changed, 7 insertions, 23 deletions
diff --git a/gobgp/cmd/common.go b/gobgp/cmd/common.go index a10460fd..a430cbbb 100644 --- a/gobgp/cmd/common.go +++ b/gobgp/cmd/common.go @@ -219,20 +219,6 @@ func ApiStruct2Path(p *gobgpapi.Path) ([]*Path, error) { return paths, nil } -type pathAttrs []bgp.PathAttributeInterface - -func (p pathAttrs) Len() int { - return len(p) -} - -func (p pathAttrs) Swap(i, j int) { - p[i], p[j] = p[j], p[i] -} - -func (p pathAttrs) Less(i, j int) bool { - return p[i].GetType() < p[j].GetType() -} - type paths []*Path func (p paths) Len() int { diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go index add15339..84fa4c19 100644 --- a/gobgp/cmd/global.go +++ b/gobgp/cmd/global.go @@ -498,7 +498,7 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) { var nlri bgp.AddrPrefixInterface var extcomms []string var err error - attrs := pathAttrs(make([]bgp.PathAttributeInterface, 0, 1)) + attrs := table.PathAttrs(make([]bgp.PathAttributeInterface, 0, 1)) path := &api.Path{ Pattrs: make([][]byte, 0), diff --git a/table/path.go b/table/path.go index e48b7258..dd510692 100644 --- a/table/path.go +++ b/table/path.go @@ -398,17 +398,17 @@ func (path *Path) GetNlri() bgp.AddrPrefixInterface { return path.OriginInfo().nlri } -type attrs []bgp.PathAttributeInterface +type PathAttrs []bgp.PathAttributeInterface -func (a attrs) Len() int { +func (a PathAttrs) Len() int { return len(a) } -func (a attrs) Swap(i, j int) { +func (a PathAttrs) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a attrs) Less(i, j int) bool { +func (a PathAttrs) Less(i, j int) bool { return a[i].GetType() < a[j].GetType() } @@ -421,7 +421,7 @@ func (path *Path) GetPathAttrs() []bgp.PathAttributeInterface { deleted.Flag(uint(t)) } if p.parent == nil { - list := make([]bgp.PathAttributeInterface, 0, len(p.pathAttrs)) + list := PathAttrs(make([]bgp.PathAttributeInterface, 0, len(p.pathAttrs))) // we assume that the original pathAttrs are // in order, that is, other bgp speakers send // attributes in order. @@ -440,9 +440,7 @@ func (path *Path) GetPathAttrs() []bgp.PathAttributeInterface { for _, m := range modified { list = append(list, m) } - var sorted attrs - sorted = list - sort.Sort(sorted) + sort.Sort(list) } return list } else { |