From c20a6d069af72cfa398656da8984a7047b0ae0b3 Mon Sep 17 00:00:00 2001 From: wizard Date: Sat, 18 Jul 2015 15:56:33 +0800 Subject: [PATCH] bump the version to 6.0 --- README.md | 2 ++ agent/netAgent.go | 7 +++---- main.go | 2 +- server/api.go | 15 ++++++--------- server/api_test.go | 22 ++-------------------- server/backend.go | 4 ++-- server/{ovs.go => connection.go} | 9 ++++----- server/daemon.go | 3 ++- server/monitor.go | 3 --- server/network.go | 6 +++--- 10 files changed, 25 insertions(+), 48 deletions(-) rename server/{ovs.go => connection.go} (98%) delete mode 100644 server/monitor.go diff --git a/README.md b/README.md index f7f1622..bb135ee 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,5 @@ Using sdn tools and netAgent to offer advanced network management for container cloud platform. +Version 6.0 ready! + diff --git a/agent/netAgent.go b/agent/netAgent.go index 936d0a3..9abceb5 100644 --- a/agent/netAgent.go +++ b/agent/netAgent.go @@ -51,12 +51,11 @@ func StartAgent(serverMode bool, bootstrap bool, bindInterface string, dataDir s watchForExistingRegisteredUpdates() - //go RegisterForNodeUpdates() go startConsul(serverMode, bootstrap, bindAddr, dataDir, errChan) select { case <-errChan: - return errors.New("Error start consul agent") + return errors.New("Error start net agent") case <-time.After(time.Second * 5): } return nil @@ -103,6 +102,8 @@ func Execute(args ...string) int { return exitCode } +const CONSUL_CATALOG_BASE_URL = "http://localhost:8500/v1/catalog/" + // Node operation related type Node struct { @@ -110,8 +111,6 @@ type Node struct { Address string `json:"Addr,ommitempty"` } -const CONSUL_CATALOG_BASE_URL = "http://localhost:8500/v1/catalog/" - func Join(addr string) error { ret := Execute("join", addr) diff --git a/main.go b/main.go index 9ff3002..a7322cd 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ func main() { app := cli.NewApp() app.Name = "cxy-sdn" app.Usage = "sdn tool for container cloud platform" - app.Version = "0.1" + app.Version = "6.0" app.Flags = []cli.Flag{ cli.StringFlag{ diff --git a/server/api.go b/server/api.go index aac9442..3f83ea8 100644 --- a/server/api.go +++ b/server/api.go @@ -14,7 +14,7 @@ type HttpErr struct { message string } -const version = "0.1" +const version = "6.0" type HttpApiFunc func(d *Daemon, w http.ResponseWriter, r *http.Request) *HttpErr @@ -124,8 +124,7 @@ func setConf(d *Daemon, w http.ResponseWriter, r *http.Request) *HttpErr { cfg := &BridgeConf{} - decoder := json.NewDecoder(r.Body) - err := decoder.Decode(cfg) + err := json.NewDecoder(r.Body).Decode(cfg) if err != nil { return &HttpErr{http.StatusInternalServerError, "setConf json decode failed"} @@ -158,7 +157,7 @@ func getNet(d *Daemon, w http.ResponseWriter, r *http.Request) *HttpErr { network, err := GetNetwork(name) if err != nil { - return &HttpErr{http.StatusInternalServerError, err.Error()} + return &HttpErr{http.StatusNotFound, err.Error()} } data, err := json.Marshal(network) @@ -180,8 +179,7 @@ func createNet(d *Daemon, w http.ResponseWriter, r *http.Request) *HttpErr { } network := &Network{} - decoder := json.NewDecoder(r.Body) - err := decoder.Decode(network) + err := json.NewDecoder(r.Body).Decode(network) if err != nil { return &HttpErr{http.StatusInternalServerError, err.Error()} @@ -298,15 +296,14 @@ func getConn(d *Daemon, w http.ResponseWriter, r *http.Request) *HttpErr { return nil } -// create a container to ovs-bridge connection +// create a container connection func createConn(d *Daemon, w http.ResponseWriter, r *http.Request) *HttpErr { if r.Body == nil { return &HttpErr{http.StatusBadRequest, "request body is empty"} } con := &Connection{} - decoder := json.NewDecoder(r.Body) - err := decoder.Decode(con) + err := json.NewDecoder(r.Body).Decode(con) if err != nil { return &HttpErr{http.StatusInternalServerError, err.Error()} diff --git a/server/api_test.go b/server/api_test.go index 76cd304..ef0bf10 100644 --- a/server/api_test.go +++ b/server/api_test.go @@ -598,7 +598,6 @@ func TestCreateQosApi(t *testing.T) { } -/* func TestUpdateQos(t *testing.T) { d := NewDaemon() connection := &Connection{ @@ -608,29 +607,12 @@ func TestUpdateQos(t *testing.T) { Network: "default", } d.connections["abc123"] = connection - request, _ := http.NewRequest("DELETE", "/connection/abc123", nil) + request, _ := http.NewRequest("PUT", "/qos/abc123?bw=200&delay=20", nil) response := httptest.NewRecorder() - go func() { - for { - context := <-d.connectionChan - if context == nil { - t.Fatalf("Object taken from channel is nil") - } - if context.Action != deleteConn { - t.Fatal("should be adding a new connection") - } - - if !reflect.DeepEqual(context.Connection, connection) { - t.Fatal("payload is incorrect") - } - context.Result <- connection - } - }() - createRouter(d).ServeHTTP(response, request) if response.Code != http.StatusOK { t.Fatalf("Expected %v:\n\tReceived: %v", "200", response.Code) } -}*/ +} diff --git a/server/backend.go b/server/backend.go index 9bd3024..2cae4fa 100644 --- a/server/backend.go +++ b/server/backend.go @@ -30,12 +30,12 @@ func join(addr string) error { func leave() error { if err := netAgent.Leave(); err != nil { - //glog.Error(err) + return err } //clean the data storage if err := os.RemoveAll(dataDir); err != nil { - // glog.Error(err) + return err } return nil diff --git a/server/ovs.go b/server/connection.go similarity index 98% rename from server/ovs.go rename to server/connection.go index 777bef0..26c0b9e 100644 --- a/server/ovs.go +++ b/server/connection.go @@ -16,7 +16,6 @@ import ( "time" "github.com/WIZARD-CXY/cxy-sdn/util" - // "github.com/golang/glog" "github.com/socketplane/libovsdb" "github.com/vishvananda/netns" ) @@ -483,7 +482,7 @@ func addQos(d *Daemon, containerId, bw, delay string) error { fmt.Println("install qos bw error in addQos") return err } - // magic number + // magic number just a large bw con.BandWidth = "8000000" } @@ -580,11 +579,11 @@ func monitorNetworkTraffic(d *Daemon) { con.(*Connection).TXTotal = tx con.(*Connection).RXTotal = rx - con.(*Connection).RXRate = float64(rx-preRx) * 8 / 3 - con.(*Connection).TXRate = float64(tx-preTx) * 8 / 3 + con.(*Connection).RXRate = float64(rx-preRx) * 8 / 2 + con.(*Connection).TXRate = float64(tx-preTx) * 8 / 2 } d.connections.RUnlock() - time.Sleep(3 * time.Second) + time.Sleep(2 * time.Second) } } diff --git a/server/daemon.go b/server/daemon.go index 9f1c82b..a023262 100644 --- a/server/daemon.go +++ b/server/daemon.go @@ -69,7 +69,7 @@ type Daemon struct { clusterChan chan *NodeCtx connectionChan chan *ConnectionCtx readyChan chan bool - Gateways map[string]struct{} + Gateways map[string]struct{} //network set } type NodeCtx struct { @@ -115,6 +115,7 @@ func (d *Daemon) Run(ctx *cli.Context) { fmt.Println("error in Init netAgent") } + // wait a while for agent to fully start time.Sleep(3 * time.Second) if d.isBootstrap { d.readyChan <- true diff --git a/server/monitor.go b/server/monitor.go deleted file mode 100644 index 677d2ac..0000000 --- a/server/monitor.go +++ /dev/null @@ -1,3 +0,0 @@ -package server - -// monitor each container network interface's egress and ingress traffic diff --git a/server/network.go b/server/network.go index b300189..20a8c36 100644 --- a/server/network.go +++ b/server/network.go @@ -164,7 +164,7 @@ func CreateNetwork(name string, subnet *net.IPNet) (*Network, error) { } // this function is used to create network from network datastore -// assume the network whose name is `name` is already exist but have no interface +// assume the network whose name is `name` is already exist but have no interface on the node func CreateNetwork2(name string, subnet *net.IPNet) (*Network, error) { network, err := GetNetwork(name) @@ -242,8 +242,8 @@ func DeleteNetwork(name string) error { return err } - eccerror := netAgent.Delete(networkStore, name) - if eccerror != netAgent.OK { + errcode := netAgent.Delete(networkStore, name) + if errcode != netAgent.OK { return errors.New("Error deleting network") } releaseVlan(network.VlanID)