summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--api/grpc_server.go5
-rw-r--r--table/policy.go4
-rw-r--r--test/lib/gobgp.py10
-rw-r--r--test/scenario_test/global_policy_test.py16
-rw-r--r--test/scenario_test/route_server_policy_test.py56
5 files changed, 61 insertions, 30 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go
index 34139d4e..af16dccf 100644
--- a/api/grpc_server.go
+++ b/api/grpc_server.go
@@ -1068,7 +1068,10 @@ func toStatementApi(s *config.Statement) *Statement {
if s.Actions.RouteDisposition.AcceptRoute {
return RouteAction_ACCEPT
}
- return RouteAction_REJECT
+ if s.Actions.RouteDisposition.RejectRoute {
+ return RouteAction_REJECT
+ }
+ return RouteAction_NONE
}(),
Community: func() *CommunityAction {
if len(s.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList) == 0 {
diff --git a/table/policy.go b/table/policy.go
index a90d7fe3..07b0f046 100644
--- a/table/policy.go
+++ b/table/policy.go
@@ -1570,6 +1570,8 @@ func (a *RoutingAction) Apply(path *Path, _ *PolicyOptions) *Path {
func NewRoutingAction(c config.RouteDisposition) (*RoutingAction, error) {
if c.AcceptRoute == c.RejectRoute && c.AcceptRoute {
return nil, fmt.Errorf("invalid route disposition")
+ } else if !c.AcceptRoute && !c.RejectRoute {
+ return nil, nil
}
accept := false
if c.AcceptRoute && !c.RejectRoute {
@@ -2174,7 +2176,7 @@ func (s *Statement) ToConfig() *config.Statement {
act := config.Actions{}
if s.RouteAction != nil && !reflect.ValueOf(s.RouteAction).IsNil() {
a := s.RouteAction.(*RoutingAction)
- act.RouteDisposition = config.RouteDisposition{AcceptRoute: a.AcceptRoute, RejectRoute: false}
+ act.RouteDisposition = config.RouteDisposition{AcceptRoute: a.AcceptRoute, RejectRoute: !a.AcceptRoute}
}
for _, a := range s.ModActions {
switch a.(type) {
diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py
index 29a116a8..9d2b4237 100644
--- a/test/lib/gobgp.py
+++ b/test/lib/gobgp.py
@@ -100,6 +100,12 @@ class GoBGPContainer(BGPContainer):
return p['value']
return None
+ def _get_med(self, path):
+ for p in path['attrs']:
+ if p['type'] == BGP_ATTR_TYPE_MULTI_EXIT_DISC:
+ return p['metric']
+ return None
+
def _trigger_peer_cmd(self, cmd, peer):
if peer not in self.peers:
raise Exception('not found peer {0}'.format(peer.router_id))
@@ -132,6 +138,7 @@ class GoBGPContainer(BGPContainer):
p["nexthop"] = self._get_nexthop(p)
p["aspath"] = self._get_as_path(p)
p["local-pref"] = self._get_local_pref(p)
+ p["med"] = self._get_med(p)
p["prefix"] = k
dsts.append({'paths': v, 'prefix': k})
return dsts
@@ -146,6 +153,7 @@ class GoBGPContainer(BGPContainer):
p["nexthop"] = self._get_nexthop(p)
p["aspath"] = self._get_as_path(p)
p["local-pref"] = self._get_local_pref(p)
+ p["med"] = self._get_med(p)
p["prefix"] = k
dsts.append({'paths': v, 'prefix': k})
return dsts
@@ -165,6 +173,7 @@ class GoBGPContainer(BGPContainer):
p["nexthop"] = self._get_nexthop(p)
p["aspath"] = self._get_as_path(p)
p["local-pref"] = self._get_local_pref(p)
+ p["med"] = self._get_med(p)
queue.put(p)
t = Thread(target=monitor)
@@ -185,6 +194,7 @@ class GoBGPContainer(BGPContainer):
p["aspath"] = self._get_as_path(p)
p["prefix"] = p['nlri']['prefix']
p["local-pref"] = self._get_local_pref(p)
+ p["med"] = self._get_med(p)
return ret
def get_adj_rib_in(self, peer, prefix='', rf='ipv4'):
diff --git a/test/scenario_test/global_policy_test.py b/test/scenario_test/global_policy_test.py
index 4c5bbb55..0d1e1ba9 100644
--- a/test/scenario_test/global_policy_test.py
+++ b/test/scenario_test/global_policy_test.py
@@ -248,6 +248,22 @@ class GoBGPTestBase(unittest.TestCase):
num4 = len(self.gobgp.get_adj_rib_out(q1))
self.assertTrue(num1 + 1 == num4)
+ def test_17_multi_statement(self):
+ self.gobgp.local('gobgp policy statement st3 add action med set 100')
+ self.gobgp.local('gobgp policy statement st4 add action local-pref 100')
+ self.gobgp.local('gobgp policy add p3 st3 st4')
+ self.gobgp.local('gobgp global policy import set p3 default accept')
+
+ self.gobgp.add_route('10.70.0.0/24')
+ time.sleep(1)
+ rib = self.gobgp.get_global_rib('10.70.0.0/24')
+ self.assertTrue(len(rib) == 1)
+ self.assertTrue(len(rib[0]['paths']) == 1)
+ path = rib[0]['paths'][0]
+ self.assertTrue(path['med'] == 100)
+ self.assertTrue(path['local-pref'] == 100)
+
+
if __name__ == '__main__':
if os.geteuid() is not 0:
diff --git a/test/scenario_test/route_server_policy_test.py b/test/scenario_test/route_server_policy_test.py
index 181af895..6bf02eb0 100644
--- a/test/scenario_test/route_server_policy_test.py
+++ b/test/scenario_test/route_server_policy_test.py
@@ -114,7 +114,7 @@ class ImportPolicy(object):
'conditions': {
'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -180,7 +180,7 @@ class ExportPolicy(object):
'conditions': {
'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -266,7 +266,7 @@ class ImportPolicyUpdate(object):
'conditions': {
'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -313,7 +313,7 @@ class ImportPolicyUpdate(object):
st0 = {'name': 'st0',
'conditions': {'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -393,7 +393,7 @@ class ExportPolicyUpdate(object):
st0 = {'name': 'st0',
'conditions': {'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -440,7 +440,7 @@ class ExportPolicyUpdate(object):
st0 = {'name': 'st0',
'conditions': {'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -536,7 +536,7 @@ class ImportPolicyIPV6(object):
'conditions': {
'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -605,7 +605,7 @@ class ExportPolicyIPV6(object):
'conditions': {
'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -687,7 +687,7 @@ class ImportPolicyIPV6Update(object):
'conditions': {
'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -731,7 +731,7 @@ class ImportPolicyIPV6Update(object):
'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {
- 'route-disposition': {'accept-route': False}}}
+ 'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -808,7 +808,7 @@ class ExportPolicyIPv6Update(object):
'conditions': {
'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -851,7 +851,7 @@ class ExportPolicyIPv6Update(object):
'conditions': {
'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -902,7 +902,7 @@ class ImportPolicyAsPathLengthCondition(object):
st0 = {'name': 'st0',
'conditions': {'bgp-conditions': {'as-path-length': {'operator': 'ge',
'value': 10}}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -962,7 +962,7 @@ class ImportPolicyAsPathCondition(object):
st0 = {'name': 'st0',
'conditions': {'bgp-conditions': {'match-as-path-set': {'as-path-set': 'as0'}}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1014,7 +1014,7 @@ class ImportPolicyAsPathAnyCondition(object):
st0 = {'name': 'st0',
'conditions': {'bgp-conditions': {'match-as-path-set': {'as-path-set': 'as0'}}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1066,7 +1066,7 @@ class ImportPolicyAsPathOriginCondition(object):
st0 = {'name': 'st0',
'conditions': {'bgp-conditions': {'match-as-path-set': {'as-path-set': 'as0'}}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1118,7 +1118,7 @@ class ImportPolicyAsPathOnlyCondition(object):
st0 = {'name': 'st0',
'conditions': {'bgp-conditions': {'match-as-path-set': {'as-path-set': 'as0'}}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1172,7 +1172,7 @@ class ImportPolicyAsPathMismatchCondition(object):
st0 = {'name': 'st0',
'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0'}}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1232,7 +1232,7 @@ class ImportPolicyCommunityCondition(object):
st0 = {'name': 'st0',
'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0'}}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1285,7 +1285,7 @@ class ImportPolicyCommunityRegexp(object):
st0 = {'name': 'st0',
'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0'}}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -2314,7 +2314,7 @@ class InPolicyReject(object):
st0 = {'name': 'st0',
'conditions':{'bgp-conditions':{'match-community-set':{'community-set': 'cs0'}}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -2448,7 +2448,7 @@ class InPolicyUpdate(object):
'conditions': {
'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -2496,7 +2496,7 @@ class InPolicyUpdate(object):
st0 = {'name': 'st0',
'conditions': {'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -2795,7 +2795,7 @@ class ImportPolicyExCommunityOriginCondition(object):
st0 = {'name': 'st0',
'conditions': {'bgp-conditions':{'match-ext-community-set':{'ext-community-set': 'es0'}}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -2846,7 +2846,7 @@ class ImportPolicyExCommunityTargetCondition(object):
st0 = {'name': 'st0',
'conditions': {'bgp-conditions':{'match-ext-community-set':{'ext-community-set': 'es0'}}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -2899,7 +2899,7 @@ class InPolicyPrefixCondition(object):
st0 = {'name': 'st0',
'conditions': {
'match-prefix-set': {'prefix-set': ps0['prefix-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -3318,7 +3318,7 @@ class InPolicyUpdate2(object):
'conditions': {
'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -3367,7 +3367,7 @@ class InPolicyUpdate2(object):
st0 = {'name': 'st0',
'conditions': {'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
- 'actions': {'route-disposition': {'accept-route': False}}}
+ 'actions': {'route-disposition': {'reject-route': True}}}
policy = {'name': 'policy0',
'statements': [st0]}