Skip to content

Commit

Permalink
Merge pull request eBay#5 from softwarejl/master
Browse files Browse the repository at this point in the history
Add meter ratelimiting parameter in acl add function
  • Loading branch information
hzhou8 authored Feb 8, 2019
2 parents 9c4240e + c12f0a9 commit cc20b82
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ func main() {
fmt.Printf("%v\n", *lp)
}

ocmd = ovndbapi.ACLAdd("ls1", "to-lport", MATCH, "drop", 1001, nil, true)
ocmd = ovndbapi.ACLAdd("ls1", "to-lport", MATCH, "drop", 1001, nil, true, "")
ovndbapi.Execute(ocmd)

ocmd = ovndbapi.ACLAdd("ls1", "to-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "a", "B": "b"}, false)
ocmd = ovndbapi.ACLAdd("ls1", "to-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "a", "B": "b"}, false, "")
ovndbapi.Execute(ocmd)


ocmd = ovndbapi.ACLAdd("ls1", "to-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "b", "B": "b"}, false)
ocmd = ovndbapi.ACLAdd("ls1", "to-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "b", "B": "b"}, false, "")
ovndbapi.Execute(ocmd)

acls := ovndbapi.GetACLsBySwitch("ls1")
Expand Down
2 changes: 1 addition & 1 deletion goovn/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type OVNDBApi interface {
// Set port security per lport
LSPSetPortSecurity(lsp string, security ...string) *OvnCommand
// Add ACL
ACLAdd(lsw, direct, match, action string, priority int, external_ids map[string]string, logflag bool) *OvnCommand
ACLAdd(lsw, direct, match, action string, priority int, external_ids map[string]string, logflag bool, meter string) *OvnCommand
// Delete acl
ACLDel(lsw, direct, match string, priority int, external_ids map[string]string) *OvnCommand
// Update address set
Expand Down
4 changes: 2 additions & 2 deletions goovn/ovnnb.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func (odb *OVNDB) LSPSetPortSecurity(lsp string, security ...string) *OvnCommand
return odb.imp.lspSetPortSecurityImp(lsp, security...)
}

func (odb *OVNDB) ACLAdd(lsw, direct, match, action string, priority int, external_ids map[string]string, logflag bool) *OvnCommand {
return odb.imp.aclAddImp(lsw, direct, match, action, priority, external_ids, logflag)
func (odb *OVNDB) ACLAdd(lsw, direct, match, action string, priority int, external_ids map[string]string, logflag bool, meter string) *OvnCommand {
return odb.imp.aclAddImp(lsw, direct, match, action, priority, external_ids, logflag, meter)
}

func (odb *OVNDB) ACLDel(lsw, direct, match string, priority int, external_ids map[string]string) *OvnCommand {
Expand Down
5 changes: 4 additions & 1 deletion goovn/ovnnbimp.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (odbi *ovnDBImp) lspSetPortSecurityImp(lsp string, security ...string) *Ovn
return &OvnCommand{operations, odbi, make([][]map[string]interface{}, len(operations))}
}

func (odbi *ovnDBImp) aclAddImp(lsw, direct, match, action string, priority int, external_ids map[string]string, logflag bool) *OvnCommand {
func (odbi *ovnDBImp) aclAddImp(lsw, direct, match, action string, priority int, external_ids map[string]string, logflag bool, meter string) *OvnCommand {
namedUUID := "acl_add" + strconv.Itoa(rand.Int())
aclrow := make(OVNRow)
aclrow["direction"] = direct
Expand All @@ -339,6 +339,9 @@ func (odbi *ovnDBImp) aclAddImp(lsw, direct, match, action string, priority int,
}
aclrow["action"] = action
aclrow["log"] = logflag
if logflag {
aclrow["meter"] = meter
}
insertOp := libovsdb.Operation{
Op: insert,
Table: ACLS,
Expand Down
16 changes: 8 additions & 8 deletions goovn/ovnnbimp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestACLs(t *testing.T) {

c = append(c, ovndbapi.LSPSetAddress(LSP, ADDR))
c = append(c, ovndbapi.LSPSetPortSecurity(LSP, ADDR))
c = append(c, ovndbapi.ACLAdd(LSW, "to-lport", MATCH, "drop", 1001, nil, true))
c = append(c, ovndbapi.ACLAdd(LSW, "to-lport", MATCH, "drop", 1001, nil, true, ""))
ovndbapi.Execute(c...)

lsps := ovndbapi.GetLogicPortsBySwitch(LSW)
Expand All @@ -70,17 +70,17 @@ func TestACLs(t *testing.T) {
assert.Equal(t, true, len(acls) == 1 && acls[0].Match == MATCH &&
acls[0].Action == "drop" && acls[0].Priority == 1001 && acls[0].Log == true, "test[%s] %s", "add acl", acls[0])

assert.Equal(t, true, nil == ovndbapi.ACLAdd(LSW, "to-lport", MATCH, "drop", 1001, nil, true),
assert.Equal(t, true, nil == ovndbapi.ACLAdd(LSW, "to-lport", MATCH, "drop", 1001, nil, true, ""),
"test[%s]", "add same acl twice, should only one added.")

c = make([]*OvnCommand, 0)
c = append(c, ovndbapi.ACLAdd(LSW, "to-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "a", "B": "b"}, false))
c = append(c, ovndbapi.ACLAdd(LSW, "to-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "a", "B": "b"}, false, ""))
ovndbapi.Execute(c...)
acls = ovndbapi.GetACLsBySwitch(LSW)
assert.Equal(t, true, len(acls) == 2, "test[%s]", "add second acl")

c = make([]*OvnCommand, 0)
c = append(c, ovndbapi.ACLAdd(LSW, "to-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "b", "B": "b"}, false))
c = append(c, ovndbapi.ACLAdd(LSW, "to-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "b", "B": "b"}, false, ""))
ovndbapi.Execute(c...)
acls = ovndbapi.GetACLsBySwitch(LSW)
assert.Equal(t, true, len(acls) == 3, "test[%s]", "add second acl")
Expand Down Expand Up @@ -158,27 +158,27 @@ func addressSetCmp(asname string, targetvalue []string) bool {
func TestAddressSet(t *testing.T) {
addressList := []string{"127.0.0.1"}
var c []*OvnCommand = make([]*OvnCommand, 0)
c = append(c, ovndbapi.ASAdd("AS1", addressList))
c = append(c, ovndbapi.ASAdd("AS1", addressList, map[string]string{}))
ovndbapi.Execute(c...)
as := ovndbapi.GetAddressSets()
assert.Equal(t, true, addressSetCmp("AS1", addressList), "test[%s] and value[%v]", "address set 1 added.", as[0].Addresses)

c = make([]*OvnCommand, 0)
c = append(c, ovndbapi.ASAdd("AS2", addressList))
c = append(c, ovndbapi.ASAdd("AS2", addressList, map[string]string{}))
ovndbapi.Execute(c...)
as = ovndbapi.GetAddressSets()
assert.Equal(t, true, addressSetCmp("AS2", addressList), "test[%s] and value[%v]", "address set 2 added.", as[1].Addresses)

addressList = []string{"127.0.0.4", "127.0.0.5", "127.0.0.6"}
c = make([]*OvnCommand, 0)
c = append(c, ovndbapi.ASUpdate("AS2", addressList))
c = append(c, ovndbapi.ASUpdate("AS2", addressList, map[string]string{}))
ovndbapi.Execute(c...)
as = ovndbapi.GetAddressSets()
assert.Equal(t, true, addressSetCmp("AS2", addressList), "test[%s] and value[%v]", "address set added with different list.", as[0].Addresses)

addressList = []string{"127.0.0.4", "127.0.0.5"}
c = make([]*OvnCommand, 0)
c = append(c, ovndbapi.ASUpdate("AS2", addressList))
c = append(c, ovndbapi.ASUpdate("AS2", addressList, map[string]string{}))
ovndbapi.Execute(c...)
as = ovndbapi.GetAddressSets()
assert.Equal(t, true, addressSetCmp("AS2", addressList), "test[%s] and value[%v]", "address set updated.", as[0].Addresses)
Expand Down

0 comments on commit cc20b82

Please sign in to comment.