Skip to content

Commit

Permalink
Merge pull request #34 from unistack-org/qos
Browse files Browse the repository at this point in the history
qos support
  • Loading branch information
softwarejl authored Mar 25, 2019
2 parents e8e90c5 + 7d430d4 commit bbc6c45
Show file tree
Hide file tree
Showing 7 changed files with 420 additions and 12 deletions.
2 changes: 1 addition & 1 deletion acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (odbi *ovnDBImp) aclDelImp(lsw, direct, match string, priority int, externa
row["match"] = match
}
//in ovn pirority is greater than/equal 0,
//if input the pirority < 0, lots of acls will be deleted if matches direct and match condition judgement.
//if input the priority < 0, lots of acls will be deleted if matches direct and match condition judgement.
if priority >= 0 {
row["priority"] = priority
}
Expand Down
12 changes: 12 additions & 0 deletions apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,18 @@ type OVNDBApi interface {
// Del dhcp options via provided external_ids
DelDHCPOptions(uuid string) (*OvnCommand, error)

// Add qos rule
QoSAdd(ls string, direction string, priority int, match string, action map[string]int, bandwidth map[string]int, external_ids map[string]string) (*OvnCommand, error)
// Del qos rule, to delete wildcard specify priority -1 and string options as ""
QoSDel(ls string, direction string, priority int, match string) (*OvnCommand, error)
// Get qos rules by logical switch name
GetQoSBySwitch(ls string) ([]*QoS, error)

// Exec command, support mul-commands in one transaction.
Execute(cmds ...*OvnCommand) error

// Get logical switch by name
GetLogicalSwitchByName(ls string) (*LogicalSwitch, error)
// Get all logical switches
GetLogicalSwitches() ([]*LogicalSwitch, error)
// Get all lport by lswitch
Expand Down Expand Up @@ -134,6 +143,9 @@ type OVNSignal interface {

OnDHCPOptionsCreate(dhcp *DHCPOptions)
OnDHCPOptionsDelete(dhcp *DHCPOptions)

OnQoSCreate(qos *QoS)
OnQoSDelete(qos *QoS)
}

// Notifier
Expand Down
78 changes: 72 additions & 6 deletions logical_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ import (
)

type LogicalSwitch struct {
UUID string
Name string
ExternalID map[interface{}]interface{}
UUID string
Name string
Ports []string
LoadBalancer []string
ACLs []string
QoSRules []string
DNSRecords []string
OtherConfig map[interface{}]interface{}
ExternalID map[interface{}]interface{}
}

func (odbi *ovnDBImp) lswListImp() (*OvnCommand, error) {
Expand Down Expand Up @@ -80,13 +86,73 @@ func (odbi *ovnDBImp) rowToLogicalSwitch(uuid string) *LogicalSwitch {
}

ls := &LogicalSwitch{
UUID: uuid,
Name: cacheLogicalSwitch.Fields["name"].(string),
ExternalID: cacheLogicalSwitch.Fields["external_ids"].(libovsdb.OvsMap).GoMap,
UUID: uuid,
Name: cacheLogicalSwitch.Fields["name"].(string),
OtherConfig: cacheLogicalSwitch.Fields["other_config"].(libovsdb.OvsMap).GoMap,
ExternalID: cacheLogicalSwitch.Fields["external_ids"].(libovsdb.OvsMap).GoMap,
}
if ports, ok := cacheLogicalSwitch.Fields["ports"]; ok {
switch ports.(type) {
case libovsdb.UUID:
ls.Ports = []string{ports.(libovsdb.UUID).GoUUID}
case libovsdb.OvsSet:
ls.Ports = odbi.ConvertGoSetToStringArray(ports.(libovsdb.OvsSet))
}
}
if lbs, ok := cacheLogicalSwitch.Fields["load_balancer"]; ok {
switch lbs.(type) {
case libovsdb.UUID:
ls.LoadBalancer = []string{lbs.(libovsdb.UUID).GoUUID}
case libovsdb.OvsSet:
ls.LoadBalancer = odbi.ConvertGoSetToStringArray(lbs.(libovsdb.OvsSet))
}
}
if acls, ok := cacheLogicalSwitch.Fields["acls"]; ok {
switch acls.(type) {
case libovsdb.UUID:
ls.ACLs = []string{acls.(libovsdb.UUID).GoUUID}
case libovsdb.OvsSet:
ls.ACLs = odbi.ConvertGoSetToStringArray(acls.(libovsdb.OvsSet))
}
}
if qosrules, ok := cacheLogicalSwitch.Fields["qos_rules"]; ok {
switch qosrules.(type) {
case libovsdb.UUID:
ls.QoSRules = []string{qosrules.(libovsdb.UUID).GoUUID}
case libovsdb.OvsSet:
ls.QoSRules = odbi.ConvertGoSetToStringArray(qosrules.(libovsdb.OvsSet))
}
}
if dnsrecords, ok := cacheLogicalSwitch.Fields["dns_records"]; ok {
switch dnsrecords.(type) {
case libovsdb.UUID:
ls.DNSRecords = []string{dnsrecords.(libovsdb.UUID).GoUUID}
case libovsdb.OvsSet:
ls.DNSRecords = odbi.ConvertGoSetToStringArray(dnsrecords.(libovsdb.OvsSet))
}
}

return ls
}

func (odbi *ovnDBImp) GetLogicalSwitchByName(ls string) (*LogicalSwitch, error) {
odbi.cachemutex.RLock()
defer odbi.cachemutex.RUnlock()

cacheLogicalSwitch, ok := odbi.cache[tableLogicalSwitch]
if !ok {
return nil, ErrorNotFound
}

for uuid, drows := range cacheLogicalSwitch {
if rlsw, ok := drows.Fields["name"].(string); ok && rlsw == ls {
return odbi.rowToLogicalSwitch(uuid), nil
}
}

return nil, ErrorNotFound
}

// Get all logical switches
func (odbi *ovnDBImp) GetLogicalSwitches() ([]*LogicalSwitch, error) {
var listLS []*LogicalSwitch
Expand Down
16 changes: 16 additions & 0 deletions ovnnb.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,26 @@ func (odb *OVNDB) LSPSetOpt(lsp string, options map[string]string) (*OvnCommand,
return odb.imp.LSPSetOpt(lsp, options)
}

func (odb *OVNDB) QoSAdd(ls string, direction string, priority int, match string, action map[string]int, bandwidth map[string]int, external_ids map[string]string) (*OvnCommand, error) {
return odb.imp.addQoSImp(ls, direction, priority, match, action, bandwidth, external_ids)
}

func (odb *OVNDB) QoSDel(ls string, direction string, priority int, match string) (*OvnCommand, error) {
return odb.imp.delQoSImp(ls, direction, priority, match)
}

func (odb *OVNDB) GetQoSBySwitch(ls string) ([]*QoS, error) {
return odb.imp.listQoSImp(ls)
}

func (odb *OVNDB) Execute(cmds ...*OvnCommand) error {
return odb.imp.Execute(cmds...)
}

func (odb *OVNDB) GetLogicalSwitchByName(ls string) (*LogicalSwitch, error) {
return odb.imp.GetLogicalSwitchByName(ls)
}

func (odb *OVNDB) GetLogicalSwitches() ([]*LogicalSwitch, error) {
return odb.imp.GetLogicalSwitches()
}
Expand Down
33 changes: 30 additions & 3 deletions ovnnbimp.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,28 @@ func newNBImp(client *ovnDBClient, callback OVNSignal) (*ovnDBImp, error) {
return nbimp, nil
}

func (odbi *ovnDBImp) getRowUUID(table string, row OVNRow) string {
func (odbi *ovnDBImp) getRowUUIDs(table string, row OVNRow) []string {
var uuids []string
var wildcard bool

if reflect.DeepEqual(row, make(OVNRow)) {
wildcard = true
}

odbi.cachemutex.RLock()
defer odbi.cachemutex.RUnlock()

cacheTable, ok := odbi.cache[table]
if !ok {
return ""
return nil
}

for uuid, drows := range cacheTable {
if wildcard {
uuids = append(uuids, uuid)
continue
}

found := false
for field, value := range row {
if v, ok := drows.Fields[field]; ok {
Expand All @@ -71,9 +83,18 @@ func (odbi *ovnDBImp) getRowUUID(table string, row OVNRow) string {
}
}
if found {
return uuid
uuids = append(uuids, uuid)
}
}

return uuids
}

func (odbi *ovnDBImp) getRowUUID(table string, row OVNRow) string {
uuids := odbi.getRowUUIDs(table, row)
if len(uuids) > 0 {
return uuids[0]
}
return ""
}

Expand Down Expand Up @@ -198,6 +219,9 @@ func (odbi *ovnDBImp) populateCache(updates libovsdb.TableUpdates) {
case tableDHCPOptions:
dhcp := odbi.rowToDHCPOptions(uuid)
odbi.callback.OnDHCPOptionsCreate(dhcp)
case tableQoS:
qos := odbi.rowToQoS(uuid)
odbi.callback.OnQoSCreate(qos)
}
}
} else {
Expand All @@ -221,6 +245,9 @@ func (odbi *ovnDBImp) populateCache(updates libovsdb.TableUpdates) {
case tableDHCPOptions:
dhcp := odbi.rowToDHCPOptions(uuid)
odbi.callback.OnDHCPOptionsDelete(dhcp)
case tableQoS:
qos := odbi.rowToQoS(uuid)
odbi.callback.OnQoSDelete(qos)
}
}
delete(odbi.cache[table], uuid)
Expand Down
Loading

0 comments on commit bbc6c45

Please sign in to comment.