summaryrefslogtreecommitdiffhomepage
path: root/api
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2018-06-21 16:18:20 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-07-06 11:08:15 +0900
commit9ae30060eb399b825f035160d5b77df74789ffb6 (patch)
treeea369db031fa2358423f6d8d65b47366e8210b4f /api
parent2e0169274a64545f64e10fa474592d9ba84c0504 (diff)
cmd: Implement PrettyString()
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'api')
-rw-r--r--api/policy.go79
1 files changed, 77 insertions, 2 deletions
diff --git a/api/policy.go b/api/policy.go
index 7296f012..102e2e02 100644
--- a/api/policy.go
+++ b/api/policy.go
@@ -25,8 +25,9 @@ import (
)
var (
- repexpCommunity = regexp.MustCompile("(\\d+.)*\\d+:\\d+")
- regexpLargeCommunity = regexp.MustCompile("\\d+:\\d+:\\d+")
+ repexpCommunity = regexp.MustCompile("(\\d+.)*\\d+:\\d+")
+ regexpLargeCommunity = regexp.MustCompile("\\d+:\\d+:\\d+")
+ regexpCommunityString = regexp.MustCompile("[\\^\\$]")
)
func ParseCommunityRegexp(arg string) (*regexp.Regexp, error) {
@@ -77,3 +78,77 @@ func ParseLargeCommunityRegexp(arg string) (*regexp.Regexp, error) {
}
return exp, nil
}
+
+func (s *MatchSet) PrettyString() string {
+ var typ string
+ switch s.Type {
+ case MatchType_ALL:
+ typ = "all"
+ case MatchType_ANY:
+ typ = "any"
+ case MatchType_INVERT:
+ typ = "invert"
+ }
+ return fmt.Sprintf("%s %s", typ, s.GetName())
+}
+
+func (s *AsPathLength) PrettyString() string {
+ var typ string
+ switch s.Type {
+ case AsPathLengthType_EQ:
+ typ = "="
+ case AsPathLengthType_GE:
+ typ = ">="
+ case AsPathLengthType_LE:
+ typ = "<="
+ }
+ return fmt.Sprintf("%s%d", typ, s.Length)
+}
+
+func (s Conditions_RouteType) PrettyString() string {
+ switch s {
+ case Conditions_ROUTE_TYPE_EXTERNAL:
+ return "external"
+ case Conditions_ROUTE_TYPE_INTERNAL:
+ return "internal"
+ case Conditions_ROUTE_TYPE_LOCAL:
+ return "local"
+ }
+ return "unknown"
+}
+
+func (a *CommunityAction) PrettyString() string {
+ l := regexpCommunityString.ReplaceAllString(strings.Join(a.Communities, ", "), "")
+ var typ string
+ switch a.Type {
+ case CommunityActionType_COMMUNITY_ADD:
+ typ = "add"
+ case CommunityActionType_COMMUNITY_REMOVE:
+ typ = "remove"
+ case CommunityActionType_COMMUNITY_REPLACE:
+ typ = "replace"
+ }
+ return fmt.Sprintf("%s[%s]", typ, l)
+}
+
+func (a *MedAction) PrettyString() string {
+ if a.Type == MedActionType_MED_MOD && a.Value > 0 {
+ return fmt.Sprintf("+%d", a.Value)
+ }
+ return fmt.Sprintf("%d", a.Value)
+}
+
+func (a *LocalPrefAction) PrettyString() string {
+ return fmt.Sprintf("%d", a.Value)
+}
+
+func (a *NexthopAction) PrettyString() string {
+ if a.Self {
+ return "self"
+ }
+ return a.Address
+}
+
+func (a *AsPrependAction) PrettyString() string {
+ return fmt.Sprintf("prepend %d %d times", a.Asn, a.Repeat)
+}