Skip to content

Commit

Permalink
compatible with OVN 20.06
Browse files Browse the repository at this point in the history
  • Loading branch information
fanriming committed Dec 21, 2021
1 parent 7919901 commit d57bc1d
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,16 @@ func (c Client) AddStaticRoute(policy, cidr, nextHop, router string, routeType s

// AddPolicyRoute add a policy route rule in ovn
func (c Client) AddPolicyRoute(router string, priority int32, match string, action string, nextHop string) error {
exist, err := c.IsPolicyRouteExist(router, priority, match)
if err != nil {
return err
}
if exist {
return nil
}

// lr-policy-add ROUTER PRIORITY MATCH ACTION [NEXTHOP]
args := []string{MayExist, "lr-policy-add", router, strconv.Itoa(int(priority)), match, action}
args := []string{"lr-policy-add", router, strconv.Itoa(int(priority)), match, action}
if nextHop != "" {
args = append(args, nextHop)
}
Expand All @@ -770,18 +778,41 @@ func (c Client) AddPolicyRoute(router string, priority int32, match string, acti

// DeletePolicyRoute delete a policy route rule in ovn
func (c Client) DeletePolicyRoute(router string, priority int32, match string) error {
var args = []string{IfExists, "lr-policy-del", router}
exist, err := c.IsPolicyRouteExist(router, priority, match)
if err != nil {
return err
}
if !exist {
return nil
}
var args = []string{"lr-policy-del", router}
// lr-policy-del ROUTER [PRIORITY [MATCH]]
if priority > 0 {
args = append(args, strconv.Itoa(int(priority)))
if match != "" {
args = append(args, match)
}
}
_, err := c.ovnNbCommand(args...)
_, err = c.ovnNbCommand(args...)
return err
}

func (c Client) IsPolicyRouteExist(router string, priority int32, match string) (bool, error) {
existPolicyRoute, err := c.GetPolicyRouteList(router)
if err != nil {
return false, err
}
for _, rule := range existPolicyRoute {
if rule.Priority != priority {
continue
}
if match == "" || rule.Match == match {
return true, nil
}
}
return false, nil
}

func (c Client) DeletePolicyRouteByNexthop(router string, priority int32, nexthop string) error {
args := []string{
"--no-heading", "--data=bare", "--columns=match", "find", "Logical_Router_Policy",
Expand Down

0 comments on commit d57bc1d

Please sign in to comment.