-
Notifications
You must be signed in to change notification settings - Fork 74
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
ofnet_test.go: write some loops as functions #86
Open
unclejack
wants to merge
1
commit into
contiv:master
Choose a base branch
from
unclejack:clean_up_ofnet_test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,66 @@ var hostBridges [NUM_HOST_BRIDGE]*HostBridge | |
|
||
var localIpList []string | ||
|
||
func createAgents(numAgents, rpcPortStart, ovsPortStart int, agentType string) { | ||
var dpName = agentType | ||
|
||
if agentType == "vrtr" { | ||
dpName = "vrouter" | ||
} | ||
|
||
for i := 0; i < numAgents; i++ { | ||
brName := fmt.Sprintf("%vBridge%v", agentType, i) | ||
rpcPort := uint16(rpcPortStart + i) | ||
ovsPort := uint16(ovsPortStart + i) | ||
localIP := net.ParseIP(localIpList[i]) | ||
|
||
agent, err := NewOfnetAgent(brName, dpName, localIP, rpcPort, ovsPort, nil) | ||
if err != nil { | ||
log.Fatalf("failed to create %v ofnet agent: %v", agentType, err) | ||
} | ||
|
||
agent.MyAddr = "127.0.0.1" | ||
|
||
switch agentType { | ||
case "vlan": | ||
vlanAgents[i] = agent | ||
case "vxlan": | ||
vxlanAgents[i] = agent | ||
case "vrtr": | ||
vrtrAgents[i] = agent | ||
} | ||
|
||
log.Infof("created %v ofnet agent: %v", agentType, agent) | ||
} | ||
} | ||
|
||
func createSwitches(numAgents, ovsPortStart, ovsDriversOffset int, brPrefix string) { | ||
errControllerAdd := "failed to add controller to OVs, brname %s: %v" | ||
for i := 0; i < numAgents; i++ { | ||
brName := fmt.Sprintf("%vBridge%v", brPrefix, i) | ||
ovsPort := uint16(ovsPortStart + i) | ||
j := ovsDriversOffset + i | ||
ovsDrivers[j] = ovsdbDriver.NewOvsDriver(brName) | ||
err := ovsDrivers[j].AddController("127.0.0.1", ovsPort) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error check can be inline |
||
log.Fatalf(errControllerAdd, brName, err) | ||
} | ||
} | ||
} | ||
|
||
func deleteBridges(numAgents, ovsDriversOffset int, brPrefix string) { | ||
errDeletingBridge := "failed to delete bridge %v: %v" | ||
for i := 0; i < numAgents; i++ { | ||
brName := fmt.Sprintf("%vBridge%v", brPrefix, i) | ||
log.Infof("deleting OVS bridge: %s", brName) | ||
err := ovsDrivers[ovsDriversOffset+i].DeleteBridge(brName) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error check can be inline |
||
log.Fatalf(errDeletingBridge, brName, err) | ||
} | ||
} | ||
|
||
} | ||
|
||
// Create couple of ofnet masters and few agents | ||
func TestMain(m *testing.M) { | ||
var err error | ||
|
@@ -103,55 +163,9 @@ func TestMain(m *testing.M) { | |
time.Sleep(1 * time.Second) | ||
|
||
// Create agents | ||
for i := 0; i < NUM_AGENT; i++ { | ||
brName := "vrtrBridge" + fmt.Sprintf("%d", i) | ||
rpcPort := uint16(VRTR_RPC_PORT + i) | ||
ovsPort := uint16(VRTR_OVS_PORT + i) | ||
lclIp := net.ParseIP(localIpList[i]) | ||
vrtrAgents[i], err = NewOfnetAgent(brName, "vrouter", lclIp, rpcPort, ovsPort, nil) | ||
if err != nil { | ||
log.Fatalf("Error creating ofnet agent. Err: %v", err) | ||
} | ||
|
||
// Override MyAddr to local host | ||
vrtrAgents[i].MyAddr = "127.0.0.1" | ||
|
||
log.Infof("Created vrouter ofnet agent: %v", vrtrAgents[i]) | ||
} | ||
|
||
for i := 0; i < NUM_AGENT; i++ { | ||
brName := "vxlanBridge" + fmt.Sprintf("%d", i) | ||
rpcPort := uint16(VXLAN_RPC_PORT + i) | ||
ovsPort := uint16(VXLAN_OVS_PORT + i) | ||
lclIp := net.ParseIP(localIpList[i]) | ||
|
||
vxlanAgents[i], err = NewOfnetAgent(brName, "vxlan", lclIp, rpcPort, ovsPort, nil) | ||
if err != nil { | ||
log.Fatalf("Error creating ofnet agent. Err: %v", err) | ||
} | ||
|
||
// Override MyAddr to local host | ||
vxlanAgents[i].MyAddr = "127.0.0.1" | ||
|
||
log.Infof("Created vxlan ofnet agent: %v", vxlanAgents[i]) | ||
} | ||
|
||
for i := 0; i < NUM_AGENT; i++ { | ||
brName := "vlanBridge" + fmt.Sprintf("%d", i) | ||
rpcPort := uint16(VLAN_RPC_PORT + i) | ||
ovsPort := uint16(VLAN_OVS_PORT + i) | ||
lclIp := net.ParseIP(localIpList[i]) | ||
|
||
vlanAgents[i], err = NewOfnetAgent(brName, "vlan", lclIp, rpcPort, ovsPort, nil) | ||
if err != nil { | ||
log.Fatalf("Error creating ofnet agent. Err: %v", err) | ||
} | ||
|
||
// Override MyAddr to local host | ||
vlanAgents[i].MyAddr = "127.0.0.1" | ||
|
||
log.Infof("Created vlan ofnet agent: %v", vlanAgents[i]) | ||
} | ||
createAgents(NUM_AGENT, VRTR_RPC_PORT, VRTR_OVS_PORT, "vrtr") | ||
createAgents(NUM_AGENT, VXLAN_RPC_PORT, VXLAN_OVS_PORT, "vxlan") | ||
createAgents(NUM_AGENT, VLAN_RPC_PORT, VLAN_OVS_PORT, "vlan") | ||
|
||
for i := 0; i < NUM_VLRTR_AGENT; i++ { | ||
brName := "vlrtrBridge" + fmt.Sprintf("%d", i) | ||
|
@@ -262,62 +276,19 @@ func TestMain(m *testing.M) { | |
log.Infof("Made dummy rpc call to all agents") | ||
|
||
// Create OVS switches and connect them to vrouter ofnet agents | ||
for i := 0; i < NUM_AGENT; i++ { | ||
brName := "vrtrBridge" + fmt.Sprintf("%d", i) | ||
ovsPort := uint16(VRTR_OVS_PORT + i) | ||
ovsDrivers[i] = ovsdbDriver.NewOvsDriver(brName) | ||
err := ovsDrivers[i].AddController("127.0.0.1", ovsPort) | ||
if err != nil { | ||
log.Fatalf("Error adding controller to ovs: %s", brName) | ||
} | ||
} | ||
createSwitches(NUM_AGENT, VRTR_OVS_PORT, 0, "vrtr") | ||
|
||
// Create OVS switches and connect them to vxlan ofnet agents | ||
for i := 0; i < NUM_AGENT; i++ { | ||
brName := "vxlanBridge" + fmt.Sprintf("%d", i) | ||
ovsPort := uint16(VXLAN_OVS_PORT + i) | ||
j := NUM_AGENT + i | ||
ovsDrivers[j] = ovsdbDriver.NewOvsDriver(brName) | ||
err := ovsDrivers[j].AddController("127.0.0.1", ovsPort) | ||
if err != nil { | ||
log.Fatalf("Error adding controller to ovs: %s", brName) | ||
} | ||
} | ||
createSwitches(NUM_AGENT, VXLAN_OVS_PORT, NUM_AGENT, "vxlan") | ||
|
||
// Create OVS switches and connect them to vlan ofnet agents | ||
for i := 0; i < NUM_AGENT; i++ { | ||
brName := "vlanBridge" + fmt.Sprintf("%d", i) | ||
ovsPort := uint16(VLAN_OVS_PORT + i) | ||
j := (2 * NUM_AGENT) + i | ||
ovsDrivers[j] = ovsdbDriver.NewOvsDriver(brName) | ||
err := ovsDrivers[j].AddController("127.0.0.1", ovsPort) | ||
if err != nil { | ||
log.Fatalf("Error adding controller to ovs: %s", brName) | ||
} | ||
} | ||
createSwitches(NUM_AGENT, VLAN_OVS_PORT, 2*NUM_AGENT, "vlan") | ||
|
||
// Create OVS switches and connect them to vxlan ofnet agents | ||
for i := 0; i < NUM_VLRTR_AGENT; i++ { | ||
brName := "vlrtrBridge" + fmt.Sprintf("%d", i) | ||
ovsPort := uint16(VLRTR_OVS_PORT + i) | ||
j := (3 * NUM_AGENT) + i | ||
ovsDrivers[j] = ovsdbDriver.NewOvsDriver(brName) | ||
err := ovsDrivers[j].AddController("127.0.0.1", ovsPort) | ||
if err != nil { | ||
log.Fatalf("Error adding controller to ovs: %s", brName) | ||
} | ||
} | ||
createSwitches(NUM_VLRTR_AGENT, VLRTR_OVS_PORT, 3*NUM_AGENT, "vlrtr") | ||
|
||
// Create OVS switches and connect them to hostbridge agents | ||
for i := 0; i < NUM_HOST_BRIDGE; i++ { | ||
brName := "hostBridge" + fmt.Sprintf("%d", i) | ||
ovsPort := uint16(HB_OVS_PORT + i) | ||
j := HB_AGENT_INDEX + i | ||
ovsDrivers[j] = ovsdbDriver.NewOvsDriver(brName) | ||
err := ovsDrivers[j].AddController("127.0.0.1", ovsPort) | ||
if err != nil { | ||
log.Fatalf("Error adding controller to ovs: %s", brName) | ||
} | ||
} | ||
createSwitches(NUM_HOST_BRIDGE, HB_OVS_PORT, HB_AGENT_INDEX, "host") | ||
|
||
// Wait for 20sec for switch to connect to controller | ||
time.Sleep(10 * time.Second) | ||
|
@@ -443,38 +414,11 @@ func waitAndCleanup() { | |
hostBridges[i].Delete() | ||
} | ||
|
||
for i := 0; i < NUM_AGENT; i++ { | ||
brName := "vrtrBridge" + fmt.Sprintf("%d", i) | ||
log.Infof("Deleting OVS bridge: %s", brName) | ||
err := ovsDrivers[i].DeleteBridge(brName) | ||
if err != nil { | ||
log.Fatalf("Error deleting the bridge. Err: %v", err) | ||
} | ||
} | ||
for i := 0; i < NUM_AGENT; i++ { | ||
brName := "vxlanBridge" + fmt.Sprintf("%d", i) | ||
log.Infof("Deleting OVS bridge: %s", brName) | ||
err := ovsDrivers[NUM_AGENT+i].DeleteBridge(brName) | ||
if err != nil { | ||
log.Fatalf("Error deleting the bridge. Err: %v", err) | ||
} | ||
} | ||
for i := 0; i < NUM_AGENT; i++ { | ||
brName := "vlanBridge" + fmt.Sprintf("%d", i) | ||
log.Infof("Deleting OVS bridge: %s", brName) | ||
err := ovsDrivers[(2*NUM_AGENT)+i].DeleteBridge(brName) | ||
if err != nil { | ||
log.Fatalf("Error deleting the bridge. Err: %v", err) | ||
} | ||
} | ||
for i := 0; i < NUM_VLRTR_AGENT; i++ { | ||
brName := "vlrtrBridge" + fmt.Sprintf("%d", i) | ||
log.Infof("Deleting OVS bridge: %s", brName) | ||
err := ovsDrivers[(3*NUM_AGENT)+i].DeleteBridge(brName) | ||
if err != nil { | ||
log.Fatalf("Error deleting the bridge. Err: %v", err) | ||
} | ||
} | ||
deleteBridges(NUM_AGENT, 0, "vrtr") | ||
deleteBridges(NUM_AGENT, NUM_AGENT, "vxlan") | ||
deleteBridges(NUM_AGENT, 2*NUM_AGENT, "vlan") | ||
deleteBridges(NUM_VLRTR_AGENT, 3*NUM_AGENT, "vlrtr") | ||
|
||
for i := 0; i < NUM_HOST_BRIDGE; i++ { | ||
brName := "hostBridge" + fmt.Sprintf("%d", i) | ||
log.Infof("Deleting OVS bridge: %s", brName) | ||
|
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.
I'd add a default case here which panics/logs a fatal error just to be pedantic