-
Notifications
You must be signed in to change notification settings - Fork 8
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
[Task] Support the new API to get the port status of ovs. #280
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a534e0a
implement the function to dump ovs ports
a05da14
Implement the ovs-controller and add the function to dump-ports
e845fdc
Upgrade the network-controller version
5c0de10
Implement a handler to dump ovs ports
8c84769
Complete the unit-test of fail case
8ffe5e8
Rename the app to deployment
4b06ba8
Create the network for ovs operation
8a8c105
Fix the wrong size of ID
8f5832c
Check the OVS Port
f490041
Add the API.md
11df4dd
fix testing
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package entity | ||
|
||
// PortStatsReceive contains information regarding the number of received | ||
// packets, bytes, etc. | ||
type PortStatsReceive struct { | ||
Packets uint64 `json:"packets"` | ||
Bytes uint64 `json:"bytes"` | ||
Dropped uint64 `json:"dropped"` | ||
Errors uint64 `json:"errors"` | ||
Frame uint64 `json:"-"` | ||
Over uint64 `json:"-"` | ||
CRC uint64 `json:"-"` | ||
} | ||
|
||
// PortStatsTransmit contains information regarding the number of transmitted | ||
// packets, bytes, etc. | ||
type PortStatsTransmit struct { | ||
Packets uint64 `json:"packets"` | ||
Bytes uint64 `json:"bytes"` | ||
Dropped uint64 `json:"dropped"` | ||
Errors uint64 `json:"errors"` | ||
Collisions uint64 `json:"collisions"` | ||
} | ||
type OVSPortStat struct { | ||
PortID uint32 `json:'portID"` | ||
Received PortStatsReceive `json:"received"` | ||
Transmitted PortStatsTransmit `json:"traansmitted"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ovscontroller | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/linkernetworks/vortex/src/entity" | ||
"github.com/linkernetworks/vortex/src/networkcontroller" | ||
"github.com/linkernetworks/vortex/src/serviceprovider" | ||
) | ||
|
||
func DumpPorts(sp *serviceprovider.Container, nodeName string, bridgeName string) ([]entity.OVSPortStat, error) { | ||
nodeIP, err := sp.KubeCtl.GetNodeInternalIP(nodeName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
nodeAddr := net.JoinHostPort(nodeIP, networkcontroller.DEFAULT_CONTROLLER_PORT) | ||
nc, err := networkcontroller.New(nodeAddr) | ||
|
||
return nc.DumpOVSPorts(bridgeName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package ovscontroller | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"os/exec" | ||
"runtime" | ||
"testing" | ||
"time" | ||
|
||
"github.com/linkernetworks/vortex/src/config" | ||
_ "github.com/linkernetworks/vortex/src/entity" | ||
kc "github.com/linkernetworks/vortex/src/kubernetes" | ||
"github.com/linkernetworks/vortex/src/serviceprovider" | ||
|
||
"github.com/moby/moby/pkg/namesgenerator" | ||
"github.com/stretchr/testify/suite" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
fakeclientset "k8s.io/client-go/kubernetes/fake" | ||
) | ||
|
||
const OVS_LOCAL_IP = "127.0.0.1" | ||
|
||
func init() { | ||
rand.Seed(time.Now().UnixNano()) | ||
} | ||
|
||
func execute(suite *suite.Suite, cmd *exec.Cmd) { | ||
w := bytes.NewBuffer(nil) | ||
cmd.Stderr = w | ||
err := cmd.Run() | ||
suite.NoError(err) | ||
fmt.Printf("Stderr: %s\n", string(w.Bytes())) | ||
} | ||
|
||
type OVSControllerTestSuite struct { | ||
suite.Suite | ||
sp *serviceprovider.Container | ||
nodeName string | ||
bridgeName string | ||
} | ||
|
||
func (suite *OVSControllerTestSuite) SetupSuite() { | ||
cf := config.MustRead("../../config/testing.json") | ||
suite.sp = serviceprovider.NewForTesting(cf) | ||
|
||
// init fakeclient | ||
fakeclient := fakeclientset.NewSimpleClientset() | ||
suite.sp.KubeCtl = kc.New(fakeclient) | ||
|
||
suite.bridgeName = namesgenerator.GetRandomName(0)[0:6] | ||
|
||
// Create a fake clinet | ||
// Initial nodes | ||
suite.nodeName = namesgenerator.GetRandomName(0) | ||
_, err := suite.sp.KubeCtl.Clientset.CoreV1().Nodes().Create(&corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: suite.nodeName, | ||
}, | ||
Status: corev1.NodeStatus{ | ||
Addresses: []corev1.NodeAddress{ | ||
{ | ||
Type: "InternalIP", | ||
Address: OVS_LOCAL_IP, | ||
}, | ||
}, | ||
}, | ||
}) | ||
suite.NoError(err) | ||
|
||
execute(&suite.Suite, exec.Command("ovs-vsctl", "add-br", suite.bridgeName)) | ||
} | ||
|
||
func (suite *OVSControllerTestSuite) TearDownSuite() { | ||
defer exec.Command("ovs-vsctl", "del-br", suite.bridgeName).Run() | ||
} | ||
|
||
func TestOVSNetworkSuite(t *testing.T) { | ||
if runtime.GOOS != "linux" { | ||
fmt.Println("We only testing the ovs function on Linux Host") | ||
t.Skip() | ||
return | ||
} | ||
if _, defined := os.LookupEnv("TEST_GRPC"); !defined { | ||
t.SkipNow() | ||
return | ||
} | ||
suite.Run(t, new(OVSControllerTestSuite)) | ||
} | ||
|
||
// OK | ||
func (suite *OVSControllerTestSuite) TestDumpOVSPorts() { | ||
portStats, err := DumpPorts(suite.sp, suite.nodeName, suite.bridgeName) | ||
suite.NoError(err) | ||
suite.Equal(1, len(portStats)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
|
||
response "github.com/linkernetworks/vortex/src/net/http" | ||
"github.com/linkernetworks/vortex/src/net/http/query" | ||
"github.com/linkernetworks/vortex/src/ovscontroller" | ||
"github.com/linkernetworks/vortex/src/web" | ||
) | ||
|
||
func getOVSPortStatsHandler(ctx *web.Context) { | ||
sp, req, resp := ctx.ServiceProvider, ctx.Request, ctx.Response | ||
|
||
//Get the parameter | ||
query := query.New(req.Request.URL.Query()) | ||
nodeName, exist := query.Str("nodeName") | ||
if !exist { | ||
response.BadRequest(req.Request, resp.ResponseWriter, fmt.Errorf("The nodeName must not be empty")) | ||
return | ||
} | ||
|
||
bridgeName, exist := query.Str("bridgeName") | ||
if !exist { | ||
response.BadRequest(req.Request, resp.ResponseWriter, fmt.Errorf("The bridgeName must not be empty")) | ||
return | ||
} | ||
|
||
fmt.Println(nodeName, bridgeName) | ||
portStats, err := ovscontroller.DumpPorts(sp, nodeName, bridgeName) | ||
if err != nil { | ||
response.InternalServerError(req.Request, resp.ResponseWriter, err) | ||
return | ||
} | ||
resp.WriteEntity(portStats) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package server | ||
|
||
import ( | ||
_ "encoding/json" | ||
"math/rand" | ||
"net/http" | ||
"net/http/httptest" | ||
|
||
"time" | ||
|
||
restful "github.com/emicklei/go-restful" | ||
"github.com/linkernetworks/mongo" | ||
"github.com/linkernetworks/vortex/src/config" | ||
"github.com/linkernetworks/vortex/src/entity" | ||
"github.com/linkernetworks/vortex/src/serviceprovider" | ||
_ "github.com/moby/moby/pkg/namesgenerator" | ||
"github.com/stretchr/testify/suite" | ||
_ "gopkg.in/mgo.v2/bson" | ||
//corev1 "k8s.io/api/core/v1" | ||
|
||
"testing" | ||
) | ||
|
||
func init() { | ||
rand.Seed(time.Now().UnixNano()) | ||
} | ||
|
||
type OVSTestSuite struct { | ||
suite.Suite | ||
sp *serviceprovider.Container | ||
wc *restful.Container | ||
session *mongo.Session | ||
storage entity.Storage | ||
} | ||
|
||
func (suite *OVSTestSuite) SetupSuite() { | ||
cf := config.MustRead("../../config/testing.json") | ||
sp := serviceprovider.NewForTesting(cf) | ||
|
||
suite.sp = sp | ||
//init session | ||
suite.session = sp.Mongo.NewSession() | ||
//init restful container | ||
suite.wc = restful.NewContainer() | ||
service := newOVSService(suite.sp) | ||
suite.wc.Add(service) | ||
} | ||
|
||
func (suite *OVSTestSuite) TearDownSuite() { | ||
} | ||
|
||
func TestOVSSuite(t *testing.T) { | ||
suite.Run(t, new(OVSTestSuite)) | ||
} | ||
|
||
func (suite *OVSTestSuite) TestGetOVSPortStatsFail() { | ||
//Empty data | ||
httpRequest, err := http.NewRequest("GET", "http://localhost:7890/v1/ovs/portstat", nil) | ||
suite.NoError(err) | ||
|
||
httpWriter := httptest.NewRecorder() | ||
suite.wc.Dispatch(httpWriter, httpRequest) | ||
assertResponseCode(suite.T(), http.StatusBadRequest, httpWriter) | ||
|
||
httpRequest, err = http.NewRequest("GET", "http://localhost:7890/v1/ovs/portstat?nodeName=11", nil) | ||
httpWriter = httptest.NewRecorder() | ||
suite.wc.Dispatch(httpWriter, httpRequest) | ||
assertResponseCode(suite.T(), http.StatusBadRequest, httpWriter) | ||
|
||
httpRequest, err = http.NewRequest("GET", "http://localhost:7890/v1/ovs/portstat?nodeName=11&&bridgeName=111", nil) | ||
httpWriter = httptest.NewRecorder() | ||
suite.wc.Dispatch(httpWriter, httpRequest) | ||
assertResponseCode(suite.T(), http.StatusInternalServerError, httpWriter) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"username":"[email protected]", | ||
"password":"p@ssw0rd" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
格式有錯?