Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashbugs due to old libovsdb #2

Merged
merged 1 commit into from
Aug 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions ovsbridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package goovs
import (
"fmt"

"github.com/kopwei/libovsdb"
"github.com/socketplane/libovsdb"
)

// OvsBridge is the structure represents the ovs bridge
Expand Down Expand Up @@ -32,10 +32,10 @@ func (bridge *OvsBridge) ReadFromDBRow(row *libovsdb.Row) error {
case "ports":
switch value.(type) {
case libovsdb.UUID:
bridge.PortUUIDs = append(bridge.PortUUIDs, value.(libovsdb.UUID).GoUuid)
bridge.PortUUIDs = append(bridge.PortUUIDs, value.(libovsdb.UUID).GoUUID)
case libovsdb.OvsSet:
for _, uuids := range value.(libovsdb.OvsSet).GoSet {
bridge.PortUUIDs = append(bridge.PortUUIDs, uuids.(libovsdb.UUID).GoUuid)
bridge.PortUUIDs = append(bridge.PortUUIDs, uuids.(libovsdb.UUID).GoUUID)
}
}
}
Expand Down Expand Up @@ -73,7 +73,7 @@ func (client *ovsClient) CreateBridge(brname string) error {
// port row to insert
port := make(map[string]interface{})
port["name"] = brname
port["interfaces"] = libovsdb.UUID{GoUuid: namedInterfaceUUID}
port["interfaces"] = libovsdb.UUID{GoUUID: namedInterfaceUUID}

insertPortOp := libovsdb.Operation{
Op: insertOperation,
Expand All @@ -86,7 +86,7 @@ func (client *ovsClient) CreateBridge(brname string) error {
bridge := make(map[string]interface{})
bridge["name"] = brname
bridge["stp_enable"] = false
bridge["ports"] = libovsdb.UUID{GoUuid: namedPortUUID}
bridge["ports"] = libovsdb.UUID{GoUUID: namedPortUUID}

// simple insert operation
insertBridgeOp := libovsdb.Operation{
Expand All @@ -97,10 +97,10 @@ func (client *ovsClient) CreateBridge(brname string) error {
}

// Inserting a Bridge row in Bridge table requires mutating the open_vswitch table
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUuid: namedBridgeUUID}}
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUUID: namedBridgeUUID}}
mutateSet, _ := libovsdb.NewOvsSet(mutateUUID)
mutation := libovsdb.NewMutation("bridges", insertOperation, mutateSet)
condition := libovsdb.NewCondition("_uuid", "==", libovsdb.UUID{GoUuid: getRootUUID()})
condition := libovsdb.NewCondition("_uuid", "==", libovsdb.UUID{GoUUID: getRootUUID()})

// simple mutate operation
mutateOp := libovsdb.Operation{
Expand Down Expand Up @@ -137,10 +137,10 @@ func (client *ovsClient) DeleteBridge(brname string) error {
}

// Deleting a Bridge row in Bridge table requires mutating the open_vswitch table
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUuid: bridgeUUID}}
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUUID: bridgeUUID}}
mutateSet, _ := libovsdb.NewOvsSet(mutateUUID)
mutation := libovsdb.NewMutation("bridges", deleteOperation, mutateSet)
condition := libovsdb.NewCondition("_uuid", "==", libovsdb.UUID{GoUuid: getRootUUID()})
condition := libovsdb.NewCondition("_uuid", "==", libovsdb.UUID{GoUUID: getRootUUID()})

// simple mutate operation
mutateOp := libovsdb.Operation{
Expand Down Expand Up @@ -219,7 +219,7 @@ func (client *ovsClient) UpdateBridgeController(brname, controller string) error
UUIDName: namedControllerUUID,
}
bridge := make(map[string]interface{})
bridge["controller"] = libovsdb.UUID{GoUuid: namedControllerUUID}
bridge["controller"] = libovsdb.UUID{GoUUID: namedControllerUUID}

updateBrCondition := libovsdb.NewCondition("name", "==", brname)
updateOp := libovsdb.Operation{
Expand All @@ -230,10 +230,10 @@ func (client *ovsClient) UpdateBridgeController(brname, controller string) error
}

// Update a Bridge row in Bridge table requires mutating the open_vswitch table
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUuid: namedControllerUUID}}
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUUID: namedControllerUUID}}
mutateSet, _ := libovsdb.NewOvsSet(mutateUUID)
mutation := libovsdb.NewMutation("controller", insertOperation, mutateSet)
condition := libovsdb.NewCondition("_uuid", "==", libovsdb.UUID{GoUuid: bridgeUUID})
condition := libovsdb.NewCondition("_uuid", "==", libovsdb.UUID{GoUUID: bridgeUUID})

// simple mutate operation
mutateOp := libovsdb.Operation{
Expand Down
54 changes: 38 additions & 16 deletions ovsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"sync"

"github.com/kopwei/libovsdb"
"github.com/socketplane/libovsdb"
)

const (
Expand Down Expand Up @@ -85,22 +85,29 @@ func GetOVSClient(contype, endpoint string) (OvsClient, error) {
}
var dbclient *libovsdb.OvsdbClient
var err error
if contype == "tcp" {
switch contype {
case "tcp":
if endpoint == "" {
dbclient, err = libovsdb.Connect(defaultTCPHost, defaultTCPPort)
} else {
host, port, err := net.SplitHostPort(endpoint)
var host, port string
host, port, err = net.SplitHostPort(endpoint)
if err != nil {
return nil, err
}
portInt, _ := strconv.Atoi(port)
var portInt int
if portInt, err = strconv.Atoi(port); err != nil {
return nil, err
}
dbclient, err = libovsdb.Connect(host, portInt)
}
} else if contype == "unix" {
case "unix":
if endpoint == "" {
endpoint = defaultUnixEndpoint
}
dbclient, err = libovsdb.ConnectUnix(endpoint)
dbclient, err = libovsdb.ConnectWithUnixSocket(endpoint)
default:
return nil, fmt.Errorf("GetOVSClient: Unsupported connection type %q.", contype)
}
if err != nil {
return nil, err
Expand All @@ -121,7 +128,11 @@ func GetOVSClient(contype, endpoint string) (OvsClient, error) {
client.interfaceCache = make(map[string]*OvsInterface)
}

initial, _ := dbclient.MonitorAll(defaultOvsDB, "")
var initial *libovsdb.TableUpdates
initial, err = dbclient.MonitorAll(defaultOvsDB, "")
if err != nil {
return nil, err
}
populateCache(*initial)
return client, nil
}
Expand All @@ -147,7 +158,7 @@ func (client *ovsClient) transact(operations []libovsdb.Operation, action string
}
}
//if ok {
// log.Println(action, "successful: ", reply[0].UUID.GoUuid)
// log.Println(action, "successful: ", reply[0].UUID.GoUUID)
//}

return nil
Expand All @@ -170,34 +181,40 @@ func (n notifier) Disconnect([]interface{}) {
func (n notifier) Disconnected(*libovsdb.OvsdbClient) {
}

func (client *ovsClient) updateOvsObjCacheByRow(objtype, uuid string, row *libovsdb.Row) error {
func (client *ovsClient) updateOvsObjCacheByRow(objtype, uuid string, row *libovsdb.Row) (err error) {
switch objtype {
case bridgeTableName:
brObj := &OvsBridge{UUID: uuid}
brObj.ReadFromDBRow(row)
if err = brObj.ReadFromDBRow(row); err != nil {
return
}
bridgeCacheUpdateLock.Lock()
client.bridgeCache[uuid] = brObj
bridgeCacheUpdateLock.Unlock()
//data, _ := json.MarshalIndent(brObj, "", " ")
//fmt.Println(string(data))
case portTableName:
portObj := &OvsPort{UUID: uuid}
portObj.ReadFromDBRow(row)
if err = portObj.ReadFromDBRow(row); err != nil {
return
}
portCacheUpdateLock.Lock()
client.portCache[uuid] = portObj
portCacheUpdateLock.Unlock()
//data, _ := json.MarshalIndent(portObj, "", " ")
//fmt.Println(string(data))
case interfaceTableName:
intfObj := &OvsInterface{UUID: uuid}
intfObj.ReadFromDBRow(row)
if err = intfObj.ReadFromDBRow(row); err != nil {
return
}
intfCacheUpdateLock.Lock()
client.interfaceCache[uuid] = intfObj
intfCacheUpdateLock.Unlock()
//data, _ := json.MarshalIndent(intfObj, "", " ")
//fmt.Println(string(data))
}
return nil
return
}

func (client *ovsClient) removeOvsObjCacheByRow(objtype, uuid string) error {
Expand All @@ -224,7 +241,7 @@ func (client *ovsClient) removeOvsObjCacheByRow(objtype, uuid string) error {
return nil
}

func populateCache(updates libovsdb.TableUpdates) {
func populateCache(updates libovsdb.TableUpdates) (err error) {
for table, tableUpdate := range updates.Updates {
if _, ok := cache[table]; !ok {
cache[table] = make(map[string]libovsdb.Row)
Expand All @@ -235,14 +252,19 @@ func populateCache(updates libovsdb.TableUpdates) {
if !reflect.DeepEqual(row.New, empty) {
// fmt.Println(table + " with uuid " + uuid + "is updated")
cache[table][uuid] = row.New
client.updateOvsObjCacheByRow(table, uuid, &row.New)
if err = client.updateOvsObjCacheByRow(table, uuid, &row.New); err != nil {
return
}
} else {
delete(cache[table], uuid)
// fmt.Println(table + " with uuid " + uuid + "is removed")
client.removeOvsObjCacheByRow(table, uuid)
if err = client.removeOvsObjCacheByRow(table, uuid); err != nil {
return
}
}
}
}
return
}

func getRootUUID() string {
Expand Down
12 changes: 9 additions & 3 deletions ovsclient_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package goovs

import (
"fmt"
"os"
"testing"

"github.com/kopwei/libovsdb"
"github.com/socketplane/libovsdb"
)

func preparingEnv() *ovsClient {
client, _ := GetOVSClient("tcp", "ovs:6640")
client, err := GetOVSClient("unix", "")
if err != nil {
fmt.Println("preparingEnv: Couldn't connect to OVS.")
os.Exit(1)
}
return client.(*ovsClient)
}

Expand All @@ -16,7 +22,7 @@ func tearDown(client OvsClient) {
}

func TestGetOVSClient(t *testing.T) {
client, _ := GetOVSClient("tcp", "ovs:6640")
client, _ := GetOVSClient("unix", "")
if client == nil {
t.Fatal("Get ovs client test failed")
}
Expand Down
6 changes: 3 additions & 3 deletions ovsintf.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"reflect"

"github.com/kopwei/libovsdb"
"github.com/socketplane/libovsdb"
)

// OvsInterface is the structure represents an interface row
Expand Down Expand Up @@ -77,7 +77,7 @@ func (client *ovsClient) addInterfaceOnPort(portName string, intf map[string]int
UUIDName: namedInterfaceUUID,
}
// Inserting a Port row in Port table requires mutating the Bridge table
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUuid: namedInterfaceUUID}}
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUUID: namedInterfaceUUID}}
mutateSet, _ := libovsdb.NewOvsSet(mutateUUID)
mutation := libovsdb.NewMutation("interfaces", insertOperation, mutateSet)
condition := libovsdb.NewCondition("name", "==", portName)
Expand Down Expand Up @@ -106,7 +106,7 @@ func (client *ovsClient) RemoveInterfaceFromPort(portname, interfaceUUID string)
}

// Inserting a Port row in Port table requires mutating the Bridge table
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUuid: namedInterfaceUUID}}
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUUID: namedInterfaceUUID}}
mutateSet, _ := libovsdb.NewOvsSet(mutateUUID)
mutation := libovsdb.NewMutation("interfaces", deleteOperation, mutateSet)
condition := libovsdb.NewCondition("name", "==", portname)
Expand Down
12 changes: 6 additions & 6 deletions ovsport.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package goovs
import (
"fmt"

"github.com/kopwei/libovsdb"
"github.com/socketplane/libovsdb"
)

// OvsPort represents a ovs port structure
Expand Down Expand Up @@ -38,10 +38,10 @@ func (port *OvsPort) ReadFromDBRow(row *libovsdb.Row) error {
case "interfaces":
switch value.(type) {
case libovsdb.UUID:
port.IntfUUIDs = append(port.IntfUUIDs, value.(libovsdb.UUID).GoUuid)
port.IntfUUIDs = append(port.IntfUUIDs, value.(libovsdb.UUID).GoUUID)
case libovsdb.OvsSet:
for _, uuids := range value.(libovsdb.OvsSet).GoSet {
port.IntfUUIDs = append(port.IntfUUIDs, uuids.(libovsdb.UUID).GoUuid)
port.IntfUUIDs = append(port.IntfUUIDs, uuids.(libovsdb.UUID).GoUUID)
}
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func (client *ovsClient) createPort(brname, portname string, vlantag int, intf m
// port row to insert
port := make(map[string]interface{})
port["name"] = portname
port["interfaces"] = libovsdb.UUID{GoUuid: namedInterfaceUUID}
port["interfaces"] = libovsdb.UUID{GoUUID: namedInterfaceUUID}
if vlantag > 0 && vlantag <= 4095 {
port["tag"] = vlantag
}
Expand All @@ -115,7 +115,7 @@ func (client *ovsClient) createPort(brname, portname string, vlantag int, intf m
UUIDName: namedPortUUID,
}
// Inserting a Port row in Port table requires mutating the Bridge table
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUuid: namedPortUUID}}
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUUID: namedPortUUID}}
mutateSet, _ := libovsdb.NewOvsSet(mutateUUID)
mutation := libovsdb.NewMutation("ports", insertOperation, mutateSet)
condition := libovsdb.NewCondition("name", "==", brname)
Expand Down Expand Up @@ -158,7 +158,7 @@ func (client *ovsClient) deletePortByUUID(brname, portUUID string) error {
}

// Inserting a Port row in Port table requires mutating the Bridge table
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUuid: portUUID}}
mutateUUID := []libovsdb.UUID{libovsdb.UUID{GoUUID: portUUID}}
mutateSet, _ := libovsdb.NewOvsSet(mutateUUID)
mutation := libovsdb.NewMutation("ports", deleteOperation, mutateSet)
condition := libovsdb.NewCondition("name", "==", brname)
Expand Down
22 changes: 0 additions & 22 deletions vendor/github.com/cenkalti/hub/.gitignore

This file was deleted.

Loading