Skip to content

Commit

Permalink
Merge pull request #7 from lebauce/notify-logical-switch
Browse files Browse the repository at this point in the history
Notify logical switch
  • Loading branch information
hzhou8 authored Mar 5, 2019
2 parents 9e129a1 + 19b8be6 commit 084c4fc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions goovn/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ type OVNDBApi interface {
// Exec command, support mul-commands in one transaction.
Execute(cmds ...*OvnCommand) error

// Get all logical switches
GetLogicSwitches() []*LogicalSwitch
// Get all lport by lswitch
GetLogicPortsBySwitch(lsw string) []*LogcalPort
// Get all acl by lswitch
Expand All @@ -74,6 +76,9 @@ type OVNDBApi interface {
}

type OVNSignal interface {
OnLogicalSwitchCreate(ls *LogicalSwitch)
OnLogicalSwitchDelete(ls *LogicalSwitch)

OnLogicalPortCreate(lp *LogcalPort)
OnLogicalPortDelete(lp *LogcalPort)

Expand All @@ -98,6 +103,12 @@ const (
OVNLOGLEVEL = 4
)

type LogicalSwitch struct {
UUID string
Name string
ExternalID map[interface{}]interface{}
}

type LogcalPort struct {
UUID string
Name string
Expand Down
4 changes: 4 additions & 0 deletions goovn/ovnnb.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func (odb *OVNDB) Execute(cmds ...*OvnCommand) error {
return odb.imp.Execute(cmds...)
}

func (odb *OVNDB) GetLogicSwitches() []*LogicalSwitch {
return odb.imp.GetLogicSwitches()
}

func (odb *OVNDB) GetLogicPortsBySwitch(lsw string) []*LogcalPort {
return odb.imp.GetLogicPortsBySwitch(lsw)
}
Expand Down
26 changes: 26 additions & 0 deletions goovn/ovnnbimp.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,9 @@ func (odbi *ovnDBImp) populateCache(updates libovsdb.TableUpdates) {
odbi.cache[table][uuid] = row.New
if odbi.callback != nil {
switch table {
case LSWITCH:
ls := odbi.RowToLogicalSwitch(uuid)
odbi.callback.OnLogicalSwitchCreate(ls)
case LPORT:
lp := odbi.RowToLogicalPort(uuid)
odbi.callback.OnLogicalPortCreate(lp)
Expand All @@ -588,6 +591,9 @@ func (odbi *ovnDBImp) populateCache(updates libovsdb.TableUpdates) {
} else {
if odbi.callback != nil {
switch table {
case LSWITCH:
ls := odbi.RowToLogicalSwitch(uuid)
odbi.callback.OnLogicalSwitchDelete(ls)
case LPORT:
lp := odbi.RowToLogicalPort(uuid)
odbi.callback.OnLogicalPortDelete(lp)
Expand All @@ -613,6 +619,15 @@ func (odbi *ovnDBImp) ConvertGoSetToStringArray(oset libovsdb.OvsSet) []string {
return ret
}

func (odbi *ovnDBImp) RowToLogicalSwitch(uuid string) *LogicalSwitch {
ls := &LogicalSwitch{
UUID: uuid,
Name: odbi.cache[LSWITCH][uuid].Fields["name"].(string),
ExternalID: odbi.cache[LSWITCH][uuid].Fields["external_ids"].(libovsdb.OvsMap).GoMap,
}
return ls
}

func (odbi *ovnDBImp) RowToLogicalPort(uuid string) *LogcalPort {
lp := &LogcalPort{
UUID: uuid,
Expand All @@ -639,6 +654,17 @@ func (odbi *ovnDBImp) RowToLogicalPort(uuid string) *LogcalPort {
return lp
}

// Get all logical switches
func (odbi *ovnDBImp) GetLogicSwitches() []*LogicalSwitch {
var lslist = []*LogicalSwitch{}
odbi.cachemutex.Lock()
defer odbi.cachemutex.Unlock()
for uuid, _ := range odbi.cache[LSWITCH] {
lslist = append(lslist, odbi.RowToLogicalSwitch(uuid))
}
return lslist
}

// Get all lport by lswitch
func (odbi *ovnDBImp) GetLogicPortsBySwitch(lsw string) []*LogcalPort {
var lplist = []*LogcalPort{}
Expand Down

0 comments on commit 084c4fc

Please sign in to comment.