diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index a7eb423..8c67bd5 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,28 +1,24 @@ { "ImportPath": "github.com/kopwei/goovs", "GoVersion": "go1.6", - "GodepVersion": "v60", - "Packages": [ - "./..." - ], + "GodepVersion": "v71", "Deps": [ { - "ImportPath": "github.com/cenkalti/hub", - "Comment": "v1.0.0-14-g57d753b", - "Rev": "57d753b5f4856e77b3cf8ecce78c97215a7d324d" + "ImportPath": "github.com/cenk/hub", + "Comment": "v1.0.0-19-g11382a9", + "Rev": "11382a9960d39b0ecda16fd01c424c11ff765a34" }, { - "ImportPath": "github.com/cenkalti/rpc2", - "Rev": "2d1be381ce47537e9e076b2b76dc70933162e4e9" + "ImportPath": "github.com/cenk/rpc2", + "Rev": "7ab76d2e88c77ca1a715756036d8264b2886acd2" }, { - "ImportPath": "github.com/cenkalti/rpc2/jsonrpc", - "Rev": "2d1be381ce47537e9e076b2b76dc70933162e4e9" + "ImportPath": "github.com/cenk/rpc2/jsonrpc", + "Rev": "7ab76d2e88c77ca1a715756036d8264b2886acd2" }, { - "ImportPath": "github.com/kopwei/libovsdb", - "Comment": "v0.1-5-g6b8c174", - "Rev": "6b8c1740034c601c462bea2455d4b8e7c83907f4" + "ImportPath": "github.com/socketplane/libovsdb", + "Rev": "5113f8fb4d9d374417ab4ce35424fbea1aad7272" } ] } diff --git a/ovsbridge.go b/ovsbridge.go index faf4977..42559c2 100644 --- a/ovsbridge.go +++ b/ovsbridge.go @@ -3,7 +3,7 @@ package goovs import ( "fmt" - "github.com/kopwei/libovsdb" + "github.com/socketplane/libovsdb" ) // OvsBridge is the structure represents the ovs bridge @@ -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) } } } @@ -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, @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ diff --git a/ovsclient.go b/ovsclient.go index 7106ef7..be94e0b 100644 --- a/ovsclient.go +++ b/ovsclient.go @@ -7,7 +7,7 @@ import ( "strconv" "sync" - "github.com/kopwei/libovsdb" + "github.com/socketplane/libovsdb" ) const ( @@ -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 @@ -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 } @@ -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 @@ -170,11 +181,13 @@ 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() @@ -182,7 +195,9 @@ func (client *ovsClient) updateOvsObjCacheByRow(objtype, uuid string, row *libov //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() @@ -190,14 +205,16 @@ func (client *ovsClient) updateOvsObjCacheByRow(objtype, uuid string, row *libov //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 { @@ -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) @@ -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 { diff --git a/ovsclient_test.go b/ovsclient_test.go index 6697af3..7e15cb7 100644 --- a/ovsclient_test.go +++ b/ovsclient_test.go @@ -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) } @@ -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") } diff --git a/ovsintf.go b/ovsintf.go index d1000a2..7ba65cf 100644 --- a/ovsintf.go +++ b/ovsintf.go @@ -4,7 +4,7 @@ import ( "fmt" "reflect" - "github.com/kopwei/libovsdb" + "github.com/socketplane/libovsdb" ) // OvsInterface is the structure represents an interface row @@ -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) @@ -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) diff --git a/ovsport.go b/ovsport.go index 94bff08..b3ce70d 100644 --- a/ovsport.go +++ b/ovsport.go @@ -3,7 +3,7 @@ package goovs import ( "fmt" - "github.com/kopwei/libovsdb" + "github.com/socketplane/libovsdb" ) // OvsPort represents a ovs port structure @@ -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) } } } @@ -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 } @@ -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) @@ -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) diff --git a/vendor/github.com/cenkalti/hub/.gitignore b/vendor/github.com/cenkalti/hub/.gitignore deleted file mode 100644 index 0026861..0000000 --- a/vendor/github.com/cenkalti/hub/.gitignore +++ /dev/null @@ -1,22 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe diff --git a/vendor/github.com/cenkalti/hub/.travis.yml b/vendor/github.com/cenkalti/hub/.travis.yml deleted file mode 100644 index b05e4c5..0000000 --- a/vendor/github.com/cenkalti/hub/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: 1.2 - diff --git a/vendor/github.com/cenkalti/hub/LICENSE b/vendor/github.com/cenkalti/hub/LICENSE deleted file mode 100644 index 89b8179..0000000 --- a/vendor/github.com/cenkalti/hub/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Cenk Altı - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/cenkalti/hub/README.md b/vendor/github.com/cenkalti/hub/README.md deleted file mode 100644 index d3f2118..0000000 --- a/vendor/github.com/cenkalti/hub/README.md +++ /dev/null @@ -1,5 +0,0 @@ -hub -=== - -[![GoDoc](https://godoc.org/github.com/cenkalti/hub?status.png)](https://godoc.org/github.com/cenkalti/hub) -[![Build Status](https://travis-ci.org/cenkalti/hub.png)](https://travis-ci.org/cenkalti/hub) diff --git a/vendor/github.com/cenkalti/hub/hub.go b/vendor/github.com/cenkalti/hub/hub.go deleted file mode 100644 index 3ad2f77..0000000 --- a/vendor/github.com/cenkalti/hub/hub.go +++ /dev/null @@ -1,81 +0,0 @@ -// Package hub provides a simple event dispatcher for publish/subscribe pattern. -package hub - -import "sync" - -type Kind int - -// Event is an interface for published events. -type Event interface { - Kind() Kind -} - -// Hub is an event dispatcher, publishes events to the subscribers -// which are subscribed for a specific event type. -// Optimized for publish calls. -// The handlers may be called in order different than they are registered. -type Hub struct { - subscribers map[Kind][]handler - m sync.RWMutex - seq uint64 -} - -type handler struct { - f func(Event) - id uint64 -} - -// Subscribe registers f for the event of a specific kind. -func (h *Hub) Subscribe(kind Kind, f func(Event)) (cancel func()) { - var cancelled bool - h.m.Lock() - h.seq++ - id := h.seq - if h.subscribers == nil { - h.subscribers = make(map[Kind][]handler) - } - h.subscribers[kind] = append(h.subscribers[kind], handler{id: id, f: f}) - h.m.Unlock() - return func() { - h.m.Lock() - if cancelled { - return - } - cancelled = true - a := h.subscribers[kind] - for i, h := range a { - if h.id == id { - a[i], a = a[len(a)-1], a[:len(a)-1] - break - } - } - if len(a) == 0 { - delete(h.subscribers, kind) - } - h.m.Unlock() - } -} - -// Publish an event to the subscribers. -func (h *Hub) Publish(e Event) { - h.m.RLock() - if handlers, ok := h.subscribers[e.Kind()]; ok { - for _, h := range handlers { - h.f(e) - } - } - h.m.RUnlock() -} - -// DefaultHub is the default Hub used by Publish and Subscribe. -var DefaultHub Hub - -// Subscribe registers f for the event of a specific kind in the DefaultHub. -func Subscribe(kind Kind, f func(Event)) (cancel func()) { - return DefaultHub.Subscribe(kind, f) -} - -// Publish an event to the subscribers in DefaultHub. -func Publish(e Event) { - DefaultHub.Publish(e) -} diff --git a/vendor/github.com/cenkalti/rpc2/LICENSE b/vendor/github.com/cenkalti/rpc2/LICENSE deleted file mode 100644 index d565b1b..0000000 --- a/vendor/github.com/cenkalti/rpc2/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Cenk Altı - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/vendor/github.com/cenkalti/rpc2/jsonrpc/jsonrpc.go b/vendor/github.com/cenkalti/rpc2/jsonrpc/jsonrpc.go deleted file mode 100644 index c6d56b7..0000000 --- a/vendor/github.com/cenkalti/rpc2/jsonrpc/jsonrpc.go +++ /dev/null @@ -1,214 +0,0 @@ -// Package jsonrpc implements a JSON-RPC ClientCodec and ServerCodec for the rpc2 package. -// -// Beside struct types, JSONCodec allows using positional arguments. -// Use []interface{} as the type of argument when sending and receiving methods. -// -// Positional arguments example: -// server.Handle("add", func(client *rpc2.Client, args []interface{}, result *float64) error { -// *result = args[0].(float64) + args[1].(float64) -// return nil -// }) -// -// var result float64 -// client.Call("add", []interface{}{1, 2}, &result) -// -package jsonrpc - -import ( - "encoding/json" - "errors" - "fmt" - "io" - "sync" - - "github.com/cenkalti/rpc2" -) - -type jsonCodec struct { - dec *json.Decoder // for reading JSON values - enc *json.Encoder // for writing JSON values - c io.Closer - - // temporary work space - msg message - serverRequest serverRequest - clientResponse clientResponse - - // JSON-RPC clients can use arbitrary json values as request IDs. - // Package rpc expects uint64 request IDs. - // We assign uint64 sequence numbers to incoming requests - // but save the original request ID in the pending map. - // When rpc responds, we use the sequence number in - // the response to find the original request ID. - mutex sync.Mutex // protects seq, pending - pending map[uint64]*json.RawMessage - seq uint64 -} - -// NewJSONCodec returns a new rpc2.Codec using JSON-RPC on conn. -func NewJSONCodec(conn io.ReadWriteCloser) rpc2.Codec { - return &jsonCodec{ - dec: json.NewDecoder(conn), - enc: json.NewEncoder(conn), - c: conn, - pending: make(map[uint64]*json.RawMessage), - } -} - -// serverRequest and clientResponse combined -type message struct { - Method string `json:"method"` - Params *json.RawMessage `json:"params"` - Id *json.RawMessage `json:"id"` - Result *json.RawMessage `json:"result"` - Error interface{} `json:"error"` -} - -// Unmarshal to -type serverRequest struct { - Method string `json:"method"` - Params *json.RawMessage `json:"params"` - Id *json.RawMessage `json:"id"` -} -type clientResponse struct { - Id uint64 `json:"id"` - Result *json.RawMessage `json:"result"` - Error interface{} `json:"error"` -} - -// to Marshal -type serverResponse struct { - Id *json.RawMessage `json:"id"` - Result interface{} `json:"result"` - Error interface{} `json:"error"` -} -type clientRequest struct { - Method string `json:"method"` - Params []interface{} `json:"params"` - Id *uint64 `json:"id"` -} - -func (c *jsonCodec) ReadHeader(req *rpc2.Request, resp *rpc2.Response) error { - c.msg = message{} - if err := c.dec.Decode(&c.msg); err != nil { - return err - } - - if c.msg.Method != "" { - // request comes to server - c.serverRequest.Id = c.msg.Id - c.serverRequest.Method = c.msg.Method - c.serverRequest.Params = c.msg.Params - - req.Method = c.serverRequest.Method - - // JSON request id can be any JSON value; - // RPC package expects uint64. Translate to - // internal uint64 and save JSON on the side. - if c.serverRequest.Id == nil { - // Notification - } else { - c.mutex.Lock() - c.seq++ - c.pending[c.seq] = c.serverRequest.Id - c.serverRequest.Id = nil - req.Seq = c.seq - c.mutex.Unlock() - } - } else { - // response comes to client - err := json.Unmarshal(*c.msg.Id, &c.clientResponse.Id) - if err != nil { - return err - } - c.clientResponse.Result = c.msg.Result - c.clientResponse.Error = c.msg.Error - - resp.Error = "" - resp.Seq = c.clientResponse.Id - if c.clientResponse.Error != nil || c.clientResponse.Result == nil { - x, ok := c.clientResponse.Error.(string) - if !ok { - return fmt.Errorf("invalid error %v", c.clientResponse.Error) - } - if x == "" { - x = "unspecified error" - } - resp.Error = x - } - } - return nil -} - -var errMissingParams = errors.New("jsonrpc: request body missing params") - -func (c *jsonCodec) ReadRequestBody(x interface{}) error { - if x == nil { - return nil - } - if c.serverRequest.Params == nil { - return errMissingParams - } - var params *[]interface{} - switch x := x.(type) { - case *[]interface{}: - params = x - default: - params = &[]interface{}{x} - } - return json.Unmarshal(*c.serverRequest.Params, params) -} - -func (c *jsonCodec) ReadResponseBody(x interface{}) error { - if x == nil { - return nil - } - return json.Unmarshal(*c.clientResponse.Result, x) -} - -func (c *jsonCodec) WriteRequest(r *rpc2.Request, param interface{}) error { - req := &clientRequest{Method: r.Method} - switch param := param.(type) { - case []interface{}: - req.Params = param - default: - req.Params = []interface{}{param} - } - if r.Seq == 0 { - // Notification - req.Id = nil - } else { - seq := r.Seq - req.Id = &seq - } - return c.enc.Encode(req) -} - -var null = json.RawMessage([]byte("null")) - -func (c *jsonCodec) WriteResponse(r *rpc2.Response, x interface{}) error { - c.mutex.Lock() - b, ok := c.pending[r.Seq] - if !ok { - c.mutex.Unlock() - return errors.New("invalid sequence number in response") - } - delete(c.pending, r.Seq) - c.mutex.Unlock() - - if b == nil { - // Invalid request so no id. Use JSON null. - b = &null - } - resp := serverResponse{Id: b} - if r.Error == "" { - resp.Result = x - } else { - resp.Error = r.Error - } - return c.enc.Encode(resp) -} - -func (c *jsonCodec) Close() error { - return c.c.Close() -} diff --git a/vendor/github.com/kopwei/libovsdb/.gitignore b/vendor/github.com/kopwei/libovsdb/.gitignore deleted file mode 100644 index 6585b84..0000000 --- a/vendor/github.com/kopwei/libovsdb/.gitignore +++ /dev/null @@ -1,59 +0,0 @@ -### https://raw.github.com/github/gitignore/master/Go.gitignore - -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so -*.swp - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof - -### https://raw.github.com/github/gitignore/master/Global/OSX.gitignore - -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - - -# Thumbnails -._* - -# Files that might appear on external disk -.Spotlight-V100 -.Trashes - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -# Intellij -.idea/ -*.iml - -### Project-Specific - -coverage.out diff --git a/vendor/github.com/kopwei/libovsdb/HACKING.md b/vendor/github.com/kopwei/libovsdb/HACKING.md deleted file mode 100644 index 0f6f761..0000000 --- a/vendor/github.com/kopwei/libovsdb/HACKING.md +++ /dev/null @@ -1,107 +0,0 @@ -HACKING -======= - -## Getting Set Up - -Assuming you already have a Go environment set up. - - go get github.com/socketplane/libovsdb - cd $GOPATH/src/github.com/socketplane/libovsdb - -You can use [`hub`](https://hub.github.com) to fork the repo - - hub fork - -... or alternatively, fork socketplane/libovsdb on GitHub and add your fork as a remote - - git remote add git@github.com:/libovsdb - -## Hacking - -Pull a local branch before you start developing. -Convention for branches is - - `bug/1234` for a branch that addresses a specific bug - - `feature/awesome` for a branch that implements an awesome feature - -If your work is a minor, you can call the branch whatever you like (within reason). - -## Committing - -Before you submit code, you must agree to the [Developer Certificate of Origin](http://developercertificate.org) - - Developer Certificate of Origin - Version 1.1 - - Copyright (C) 2004, 2006 The Linux Foundation and its contributors. - 660 York Street, Suite 102, - San Francisco, CA 94110 USA - - Everyone is permitted to copy and distribute verbatim copies of this - license document, but changing it is not allowed. - - - Developer's Certificate of Origin 1.1 - - By making a contribution to this project, I certify that: - - (a) The contribution was created in whole or in part by me and I - have the right to submit it under the open source license - indicated in the file; or - - (b) The contribution is based upon previous work that, to the best - of my knowledge, is covered under an appropriate open source - license and I have the right under that license to submit that - work with modifications, whether created in whole or in part - by me, under the same open source license (unless I am - permitted to submit under a different license), as indicated - in the file; or - - (c) The contribution was provided directly to me by some other - person who certified (a), (b) or (c) and I have not modified - it. - - (d) I understand and agree that this project and the contribution - are public and that a record of the contribution (including all - personal information I submit with it, including my sign-off) is - maintained indefinitely and may be redistributed consistent with - this project or the open source license(s) involved. - -To verify that you agree, you must sign-off your commits. - - git commit -s - -This adds the following to the bottom of you commit message - - Signed-off-by: John Doe - -The name and email address used in the sign off are taken from your `user.name` and `user.email` settings in `git`. You can change these globally or locally using `git config` or from your `~/.gitconfig` file - -## Before Making a Pull Request - - # Run all the tests - fig up -d - make test-all - - # Make sure your code is pretty - go fmt - -## Make a Pull Request - - git push - hub pull-request - -... or if you still aren't using `hub` (which you should be by now) you can head over to [GitHub](http://github.com) and create a PR using the web interface - -## Code Review - -Once your patch has been submitted it will be scrutinized by your peers. -To make changes in response to comments... - - # Assuming you are already on the branch you raise the PR - git push --force - -This will update the pull request, retrigger CI etc... - -## Summary - -We hope you find this guide helpful and are looking forward to your pull requests! diff --git a/vendor/github.com/kopwei/libovsdb/LICENSE b/vendor/github.com/kopwei/libovsdb/LICENSE deleted file mode 100644 index e06d208..0000000 --- a/vendor/github.com/kopwei/libovsdb/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - diff --git a/vendor/github.com/kopwei/libovsdb/Makefile b/vendor/github.com/kopwei/libovsdb/Makefile deleted file mode 100644 index 7dae293..0000000 --- a/vendor/github.com/kopwei/libovsdb/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -all: build test - -build: - go build -v - -test: - go test -covermode=count -coverprofile=coverage.out -test.short -v - -test-all: - go test -covermode=count -coverprofile=coverage.out -v - diff --git a/vendor/github.com/kopwei/libovsdb/README.md b/vendor/github.com/kopwei/libovsdb/README.md deleted file mode 100644 index 306862c..0000000 --- a/vendor/github.com/kopwei/libovsdb/README.md +++ /dev/null @@ -1,33 +0,0 @@ -libovsdb -======== - -[![Circle CI](https://circleci.com/gh/socketplane/libovsdb.png?style=badge&circle-token=17838d6362be941ed8478bf9d10de5307d4b917d)](https://circleci.com/gh/socketplane/libovsdb) [![Coverage Status](https://coveralls.io/repos/socketplane/libovsdb/badge.png?branch=master)](https://coveralls.io/r/socketplane/libovsdb?branch=master) - -An OVSDB Library written in Go - -## What is OVSDB? - -OVSDB is the Open vSwitch Database Protocol. -It's defined in [RFC 7047](http://tools.ietf.org/html/rfc7047) -It's used mainly for managing the configuration of Open vSwitch, but it could also be used to manage your stamp collection. Philatelists Rejoice! - -## Running the tests - -To run only unit tests: - - make test - -To run integration tests, you'll need access to docker to run an Open vSwitch container. -Mac users can use [boot2docker](http://boot2docker.io) - - export DOCKER_IP=192.168.59.103 - fig up -d - make test-all - fig stop - -## Dependency Management - -We use [godep](https://github.com/tools/godep) for dependency management with rewritten import paths. -This allows the repo to be `go get`able. - -To bump the version of a dependency, follow these [instructions](https://github.com/tools/godep#update-a-dependency) diff --git a/vendor/github.com/kopwei/libovsdb/circle.yml b/vendor/github.com/kopwei/libovsdb/circle.yml deleted file mode 100644 index 67bae7d..0000000 --- a/vendor/github.com/kopwei/libovsdb/circle.yml +++ /dev/null @@ -1,37 +0,0 @@ ---- -machine: - services: - - docker - environment: - DOCKER_IP: "127.0.0.1" - GOPATH: "/home/ubuntu/.go_workspace" - ORG_PATH: "github.com/socketplane" - REPO_PATH: "${ORG_PATH}/libovsdb" - -dependencies: - override: - - rm -rf ${GOPATH}/src/${REPO_PATH} - - mkdir -p ${GOPATH}/src/${ORG_PATH} - - cp -r ../libovsdb ${GOPATH}/src/${ORG_PATH} - - mkdir -p ${CIRCLE_ARTIFACTS}/coverage - - go get github.com/mattn/goveralls - - post: - - sudo pip install -qq fig: - pwd: ../.go_workspace/src/${REPO_PATH} - - fig up -d: - pwd: ../.go_workspace/src/${REPO_PATH} -test: - override: - - make build: - pwd: ../.go_workspace/src/${REPO_PATH} - - make test-all: - pwd: ../.go_workspace/src/${REPO_PATH} - post: - - fig stop: - pwd: ../.go_workspace/src/${REPO_PATH} - - go tool cover -html=coverage.out -o $CIRCLE_ARTIFACTS/coverage/index.html: - pwd: ../.go_workspace/src/${REPO_PATH} - - goveralls -coverprofile=coverage.out -service=circleci -repotoken $COVERALLS_TOKEN: - pwd: ../.go_workspace/src/${REPO_PATH} - diff --git a/vendor/github.com/kopwei/libovsdb/client.go b/vendor/github.com/kopwei/libovsdb/client.go deleted file mode 100644 index 1316384..0000000 --- a/vendor/github.com/kopwei/libovsdb/client.go +++ /dev/null @@ -1,269 +0,0 @@ -package libovsdb - -import ( - "encoding/json" - "errors" - "fmt" - "log" - "net" - - "github.com/cenkalti/rpc2" - "github.com/cenkalti/rpc2/jsonrpc" -) - -type OvsdbClient struct { - rpcClient *rpc2.Client - Schema map[string]DatabaseSchema - handlers []NotificationHandler -} - -func newOvsdbClient(c *rpc2.Client) *OvsdbClient { - ovs := &OvsdbClient{rpcClient: c, Schema: make(map[string]DatabaseSchema)} - if connections == nil { - connections = make(map[*rpc2.Client]*OvsdbClient) - } - connections[c] = ovs - return ovs -} - -// Would rather replace this connection map with an OvsdbClient Receiver scoped method -// Unfortunately rpc2 package acts wierd with a receiver scoped method and needs some investigation. -var connections map[*rpc2.Client]*OvsdbClient - -const DEFAULT_ADDR = "127.0.0.1" -const DEFAULT_PORT = 6640 -const DEFAULT_UNIX_SOCKET = "/var/run/openvswitch/db.sock" - -func dial(network, address string) (*OvsdbClient, error) { - conn, err := net.Dial(network, address) - if err != nil { - return nil, err - } - - c := rpc2.NewClientWithCodec(jsonrpc.NewJSONCodec(conn)) - c.Handle("echo", echo) - c.Handle("update", update) - go c.Run() - go handleDisconnectNotification(c) - - ovs := newOvsdbClient(c) - - // Process Async Notifications - dbs, err := ovs.ListDbs() - if err == nil { - for _, db := range dbs { - schema, err := ovs.GetSchema(db) - if err == nil { - ovs.Schema[db] = *schema - } else { - return nil, err - } - } - } - return ovs, nil -} - -// ConnectUnix generated the client which connects to the unix socket -func ConnectUnix(unixSocket string) (*OvsdbClient, error) { - if unixSocket == "" { - unixSocket = DEFAULT_UNIX_SOCKET - } - return dial("unix", unixSocket) -} - -func Connect(ipAddr string, port int) (*OvsdbClient, error) { - if ipAddr == "" { - ipAddr = DEFAULT_ADDR - } - - if port <= 0 { - port = DEFAULT_PORT - } - - target := fmt.Sprintf("%s:%d", ipAddr, port) - return dial("tcp", target) -} - -func (ovs *OvsdbClient) Register(handler NotificationHandler) { - ovs.handlers = append(ovs.handlers, handler) -} - -type NotificationHandler interface { - // RFC 7047 section 4.1.6 Update Notification - Update(context interface{}, tableUpdates TableUpdates) - - // RFC 7047 section 4.1.9 Locked Notification - Locked([]interface{}) - - // RFC 7047 section 4.1.10 Stolen Notification - Stolen([]interface{}) - - // RFC 7047 section 4.1.11 Echo Notification - Echo([]interface{}) - - Disconnected(*OvsdbClient) -} - -// RFC 7047 : Section 4.1.6 : Echo -func echo(client *rpc2.Client, args []interface{}, reply *[]interface{}) error { - *reply = args - if _, ok := connections[client]; ok { - for _, handler := range connections[client].handlers { - handler.Echo(nil) - } - } - return nil -} - -// RFC 7047 : Update Notification Section 4.1.6 -// Processing "params": [, ] -func update(client *rpc2.Client, params []interface{}, reply *interface{}) error { - if len(params) < 2 { - return errors.New("Invalid Update message") - } - // Ignore params[0] as we dont use the currently for comparison - - raw, ok := params[1].(map[string]interface{}) - if !ok { - return errors.New("Invalid Update message") - } - var rowUpdates map[string]map[string]RowUpdate - - b, err := json.Marshal(raw) - if err != nil { - return err - } - err = json.Unmarshal(b, &rowUpdates) - if err != nil { - return err - } - - // Update the local DB cache with the tableUpdates - tableUpdates := getTableUpdatesFromRawUnmarshal(rowUpdates) - if _, ok := connections[client]; ok { - for _, handler := range connections[client].handlers { - handler.Update(params, tableUpdates) - } - } - - return nil -} - -// RFC 7047 : get_schema -func (ovs OvsdbClient) GetSchema(dbName string) (*DatabaseSchema, error) { - args := NewGetSchemaArgs(dbName) - var reply DatabaseSchema - err := ovs.rpcClient.Call("get_schema", args, &reply) - if err != nil { - return nil, err - } else { - ovs.Schema[dbName] = reply - } - return &reply, err -} - -// RFC 7047 : list_dbs -func (ovs OvsdbClient) ListDbs() ([]string, error) { - var dbs []string - err := ovs.rpcClient.Call("list_dbs", nil, &dbs) - if err != nil { - log.Fatal("ListDbs failure", err) - } - return dbs, err -} - -// RFC 7047 : transact - -func (ovs OvsdbClient) Transact(database string, operation ...Operation) ([]OperationResult, error) { - var reply []OperationResult - db, ok := ovs.Schema[database] - if !ok { - return nil, errors.New("invalid Database Schema") - } - - if ok := db.validateOperations(operation...); !ok { - return nil, errors.New("Validation failed for the operation") - } - - args := NewTransactArgs(database, operation...) - err := ovs.rpcClient.Call("transact", args, &reply) - if err != nil { - return nil, err - } - return reply, nil -} - -// Convenience method to monitor every table/column -func (ovs OvsdbClient) MonitorAll(database string, jsonContext interface{}) (*TableUpdates, error) { - schema, ok := ovs.Schema[database] - if !ok { - return nil, errors.New("invalid Database Schema") - } - - requests := make(map[string]MonitorRequest) - for table, tableSchema := range schema.Tables { - var columns []string - for column, _ := range tableSchema.Columns { - columns = append(columns, column) - } - requests[table] = MonitorRequest{ - Columns: columns, - Select: MonitorSelect{ - Initial: true, - Insert: true, - Delete: true, - Modify: true, - }} - } - return ovs.Monitor(database, jsonContext, requests) -} - -// RFC 7047 : monitor -func (ovs OvsdbClient) Monitor(database string, jsonContext interface{}, requests map[string]MonitorRequest) (*TableUpdates, error) { - var reply TableUpdates - - args := NewMonitorArgs(database, jsonContext, requests) - - // This totally sucks. Refer to golang JSON issue #6213 - var response map[string]map[string]RowUpdate - err := ovs.rpcClient.Call("monitor", args, &response) - reply = getTableUpdatesFromRawUnmarshal(response) - if err != nil { - return nil, err - } - return &reply, err -} - -func getTableUpdatesFromRawUnmarshal(raw map[string]map[string]RowUpdate) TableUpdates { - var tableUpdates TableUpdates - tableUpdates.Updates = make(map[string]TableUpdate) - for table, update := range raw { - tableUpdate := TableUpdate{update} - tableUpdates.Updates[table] = tableUpdate - } - return tableUpdates -} - -func clearConnection(c *rpc2.Client) { - if _, ok := connections[c]; ok { - for _, handler := range connections[c].handlers { - if handler != nil { - handler.Disconnected(connections[c]) - } - } - } - delete(connections, c) -} - -func handleDisconnectNotification(c *rpc2.Client) { - disconnected := c.DisconnectNotify() - select { - case <-disconnected: - clearConnection(c) - } -} - -func (ovs OvsdbClient) Disconnect() { - ovs.rpcClient.Close() - clearConnection(ovs.rpcClient) -} diff --git a/vendor/github.com/kopwei/libovsdb/fig.yml b/vendor/github.com/kopwei/libovsdb/fig.yml deleted file mode 100644 index c83297b..0000000 --- a/vendor/github.com/kopwei/libovsdb/fig.yml +++ /dev/null @@ -1,6 +0,0 @@ -ovs: - image: davetucker/docker-ovs:2.3.0 - ports: - - "6640:6640" - command: "/usr/bin/supervisord -n" - privileged: true diff --git a/vendor/github.com/kopwei/libovsdb/map.go b/vendor/github.com/kopwei/libovsdb/map.go deleted file mode 100644 index 736f4d2..0000000 --- a/vendor/github.com/kopwei/libovsdb/map.go +++ /dev/null @@ -1,60 +0,0 @@ -package libovsdb - -import ( - "encoding/json" - "errors" - "reflect" -) - -// RFC 7047 uses the following notation for map as JSON doesnt support non-string keys for maps. -// A 2-element JSON array that represents a database map value. The -// first element of the array must be the string "map", and the -// second element must be an array of zero or more s giving the -// values in the map. All of the s must have the same key and -// value types. - -type OvsMap struct { - GoMap map[interface{}]interface{} -} - -// notation requires special handling -func (o OvsMap) MarshalJSON() ([]byte, error) { - var ovsMap, innerMap []interface{} - ovsMap = append(ovsMap, "map") - for key, val := range o.GoMap { - var mapSeg []interface{} - mapSeg = append(mapSeg, key) - mapSeg = append(mapSeg, val) - innerMap = append(innerMap, mapSeg) - } - ovsMap = append(ovsMap, innerMap) - return json.Marshal(ovsMap) -} - -func (o *OvsMap) UnmarshalJSON(b []byte) (err error) { - var oMap []interface{} - o.GoMap = make(map[interface{}]interface{}) - if err := json.Unmarshal(b, &oMap); err == nil && len(oMap) > 1 { - innerSlice := oMap[1].([]interface{}) - for _, val := range innerSlice { - f := val.([]interface{}) - o.GoMap[f[0]] = f[1] - } - } - return err -} - -// notation requires special marshaling -func NewOvsMap(goMap interface{}) (*OvsMap, error) { - v := reflect.ValueOf(goMap) - if v.Kind() != reflect.Map { - return nil, errors.New("OvsMap supports only Go Map types") - } - - genMap := make(map[interface{}]interface{}) - keys := v.MapKeys() - for _, key := range keys { - genMap[key.Interface()] = v.MapIndex(key).Interface() - } - return &OvsMap{genMap}, nil -} diff --git a/vendor/github.com/kopwei/libovsdb/notation.go b/vendor/github.com/kopwei/libovsdb/notation.go deleted file mode 100644 index bc3d8d2..0000000 --- a/vendor/github.com/kopwei/libovsdb/notation.go +++ /dev/null @@ -1,122 +0,0 @@ -package libovsdb - -import "encoding/json" - -// Operation represents an operation according to RFC7047 section 5.2 -type Operation struct { - Op string `json:"op"` - Table string `json:"table"` - Row map[string]interface{} `json:"row,omitempty"` - Rows []map[string]interface{} `json:"rows,omitempty"` - Columns []string `json:"columns,omitempty"` - Mutations []interface{} `json:"mutations,omitempty"` - Timeout int `json:"timeout,omitempty"` - Where []interface{} `json:"where,omitempty"` - Until string `json:"until,omitempty"` - UUIDName string `json:"uuid-name,omitempty"` -} - -// MonitorRequest represents a monitor request according to RFC7047 -/* - * We cannot use MonitorRequests by inlining the MonitorRequest Map structure till GoLang issue #6213 makes it. - * The only option is to go with raw map[string]interface{} option :-( that sucks ! - * Refer to client.go : MonitorAll() function for more details - */ - -type MonitorRequests struct { - Requests map[string]MonitorRequest `json:"requests,overflow"` -} - -// MonitorRequest represents a monitor request according to RFC7047 -type MonitorRequest struct { - Columns []string `json:"columns,omitempty"` - Select MonitorSelect `json:"select,omitempty"` -} - -// MonitorSelect represents a monitor select according to RFC7047 -type MonitorSelect struct { - Initial bool `json:"initial,omitempty"` - Insert bool `json:"insert,omitempty"` - Delete bool `json:"delete,omitempty"` - Modify bool `json:"modify,omitempty"` -} - -/* - * We cannot use TableUpdates directly by json encoding by inlining the TableUpdate Map - * structure till GoLang issue #6213 makes it. - * - * The only option is to go with raw map[string]map[string]interface{} option :-( that sucks ! - * Refer to client.go : MonitorAll() function for more details - */ -type TableUpdates struct { - Updates map[string]TableUpdate `json:"updates,overflow"` -} - -type TableUpdate struct { - Rows map[string]RowUpdate `json:"rows,overflow"` -} - -type RowUpdate struct { - Uuid UUID `json:"-,omitempty"` - New Row `json:"new,omitempty"` - Old Row `json:"old,omitempty"` -} - -// OvsdbError is an OVS Error Condition -type OvsdbError struct { - Error string `json:"error"` - Details string `json:"details,omitempty"` -} - -// NewCondition creates a new condition as specified in RFC7047 -func NewCondition(column string, function string, value interface{}) []interface{} { - return []interface{}{column, function, value} -} - -// NewMutation creates a new mutation as specified in RFC7047 -func NewMutation(column string, mutator string, value interface{}) []interface{} { - return []interface{}{column, mutator, value} -} - -type TransactResponse struct { - Result []OperationResult `json:"result"` - Error string `json:"error"` -} - -type OperationResult struct { - Count int `json:"count,omitempty"` - Error string `json:"error,omitempty"` - Details string `json:"details,omitempty"` - UUID UUID `json:"uuid,omitempty"` - Rows []map[string]interface{} `json:"rows,omitempty"` -} - -func ovsSliceToGoNotation(val interface{}) (interface{}, error) { - switch val.(type) { - case []interface{}: - sl := val.([]interface{}) - bsliced, err := json.Marshal(sl) - if err != nil { - return nil, err - } - - switch sl[0] { - case "uuid": - var uuid UUID - err = json.Unmarshal(bsliced, &uuid) - return uuid, err - case "set": - var oSet OvsSet - err = json.Unmarshal(bsliced, &oSet) - return oSet, err - case "map": - var oMap OvsMap - err = json.Unmarshal(bsliced, &oMap) - return oMap, err - } - return val, nil - } - return val, nil -} - -// TODO : add Condition, Function, Mutation and Mutator notations diff --git a/vendor/github.com/kopwei/libovsdb/row.go b/vendor/github.com/kopwei/libovsdb/row.go deleted file mode 100644 index f178215..0000000 --- a/vendor/github.com/kopwei/libovsdb/row.go +++ /dev/null @@ -1,21 +0,0 @@ -package libovsdb - -import "encoding/json" - -type Row struct { - Fields map[string]interface{} -} - -func (r *Row) UnmarshalJSON(b []byte) (err error) { - r.Fields = make(map[string]interface{}) - var raw map[string]interface{} - err = json.Unmarshal(b, &raw) - for key, val := range raw { - val, err = ovsSliceToGoNotation(val) - if err != nil { - return err - } - r.Fields[key] = val - } - return err -} diff --git a/vendor/github.com/kopwei/libovsdb/rpc.go b/vendor/github.com/kopwei/libovsdb/rpc.go deleted file mode 100644 index 5664cb8..0000000 --- a/vendor/github.com/kopwei/libovsdb/rpc.go +++ /dev/null @@ -1,40 +0,0 @@ -package libovsdb - -// NewGetSchemaArgs creates a new set of arguments for a get_schemas RPC -func NewGetSchemaArgs(schema string) []interface{} { - return []interface{}{schema} -} - -// NewTransactArgs creates a new set of arguments for a transact RPC -func NewTransactArgs(database string, operations ...Operation) []interface{} { - var dbSlice = make([]interface{}, 1) - dbSlice[0] = database - - var opsSlice []interface{} = make([]interface{}, len(operations)) - for i, d := range operations { - opsSlice[i] = d - } - - ops := append(dbSlice, opsSlice...) - return ops -} - -// NewCancelArgs creates a new set of arguments for a cancel RPC -func NewCancelArgs(id interface{}) []interface{} { - return []interface{}{id} -} - -// NewMonitorArgs creates a new set of arguments for a monitor RPC -func NewMonitorArgs(database string, value interface{}, requests map[string]MonitorRequest) []interface{} { - return []interface{}{database, value, requests} -} - -// NewMonitorCancelArgs creates a new set of arguments for a monitor_cancel RPC -func NewMonitorCancelArgs(value interface{}) []interface{} { - return []interface{}{value} -} - -// NewLockArgs creates a new set of arguments for a lock, steal or unlock RPC -func NewLockArgs(id interface{}) []interface{} { - return []interface{}{id} -} diff --git a/vendor/github.com/kopwei/libovsdb/schema.go b/vendor/github.com/kopwei/libovsdb/schema.go deleted file mode 100644 index f683368..0000000 --- a/vendor/github.com/kopwei/libovsdb/schema.go +++ /dev/null @@ -1,63 +0,0 @@ -package libovsdb - -import ( - "fmt" - "io" -) - -type DatabaseSchema struct { - Name string `json:"name"` - Version string `json:"version"` - Tables map[string]TableSchema `json:"tables"` -} - -type TableSchema struct { - Columns map[string]ColumnSchema `json:"columns"` - Indexes [][]string `json:"indexes,omitempty"` -} - -type ColumnSchema struct { - Name string `json:"name"` - Type interface{} `json:"type"` - Ephemeral bool `json:"ephemeral,omitempty"` - Mutable bool `json:"mutable,omitempty"` -} - -func (schema DatabaseSchema) Print(w io.Writer) { - fmt.Fprintf(w, "%s, (%s)\n", schema.Name, schema.Version) - for table, tableSchema := range schema.Tables { - fmt.Fprintf(w, "\t %s\n", table) - for column, columnSchema := range tableSchema.Columns { - fmt.Fprintf(w, "\t\t %s => %v\n", column, columnSchema) - } - } -} - -// Basic validation for operations against Database Schema -func (schema DatabaseSchema) validateOperations(operations ...Operation) bool { - for _, op := range operations { - table, ok := schema.Tables[op.Table] - if ok { - for column, _ := range op.Row { - if _, ok := table.Columns[column]; !ok { - return false - } - } - for _, row := range op.Rows { - for column, _ := range row { - if _, ok := table.Columns[column]; !ok { - return false - } - } - } - for _, column := range op.Columns { - if _, ok := table.Columns[column]; !ok { - return false - } - } - } else { - return false - } - } - return true -} diff --git a/vendor/github.com/kopwei/libovsdb/set.go b/vendor/github.com/kopwei/libovsdb/set.go deleted file mode 100644 index 46aaeea..0000000 --- a/vendor/github.com/kopwei/libovsdb/set.go +++ /dev/null @@ -1,54 +0,0 @@ -package libovsdb - -import ( - "encoding/json" - "errors" - "reflect" -) - -// RFC 7047 has a wierd (but understandable) notation for set as described as : -// Either an , representing a set with exactly one element, or -// a 2-element JSON array that represents a database set value. The -// first element of the array must be the string "set", and the -// second element must be an array of zero or more s giving the -// values in the set. All of the s must have the same type. - -type OvsSet struct { - GoSet []interface{} -} - -// notation requires special handling -func NewOvsSet(goSlice interface{}) (*OvsSet, error) { - v := reflect.ValueOf(goSlice) - if v.Kind() != reflect.Slice { - return nil, errors.New("OvsSet supports only Go Slice types") - } - - var ovsSet []interface{} - for i := 0; i < v.Len(); i++ { - ovsSet = append(ovsSet, v.Index(i).Interface()) - } - return &OvsSet{ovsSet}, nil -} - -// notation requires special marshaling -func (o OvsSet) MarshalJSON() ([]byte, error) { - var oSet []interface{} - oSet = append(oSet, "set") - oSet = append(oSet, o.GoSet) - return json.Marshal(oSet) -} - -func (o *OvsSet) UnmarshalJSON(b []byte) (err error) { - var oSet []interface{} - if err = json.Unmarshal(b, &oSet); err == nil && len(oSet) > 1 { - innerSet := oSet[1].([]interface{}) - for _, val := range innerSet { - goVal, err := ovsSliceToGoNotation(val) - if err == nil { - o.GoSet = append(o.GoSet, goVal) - } - } - } - return err -} diff --git a/vendor/github.com/kopwei/libovsdb/uuid.go b/vendor/github.com/kopwei/libovsdb/uuid.go deleted file mode 100644 index 0ce5321..0000000 --- a/vendor/github.com/kopwei/libovsdb/uuid.go +++ /dev/null @@ -1,46 +0,0 @@ -package libovsdb - -import ( - "encoding/json" - "errors" - "regexp" -) - -type UUID struct { - GoUuid string `json:"uuid"` -} - -// notation requires special marshaling -func (u UUID) MarshalJSON() ([]byte, error) { - var uuidSlice []string - err := u.validateUUID() - if err == nil { - uuidSlice = []string{"uuid", u.GoUuid} - } else { - uuidSlice = []string{"named-uuid", u.GoUuid} - } - - return json.Marshal(uuidSlice) -} - -func (u *UUID) UnmarshalJSON(b []byte) (err error) { - var ovsUuid []string - if err := json.Unmarshal(b, &ovsUuid); err == nil { - u.GoUuid = ovsUuid[1] - } - return err -} - -func (u UUID) validateUUID() error { - if len(u.GoUuid) != 36 { - return errors.New("uuid exceeds 36 characters") - } - - var validUUID = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`) - - if !validUUID.MatchString(u.GoUuid) { - return errors.New("uuid does not match regexp") - } - - return nil -}