Skip to content

Commit 230e46c

Browse files
authored
Merge pull request #959 from contiv/master
release 1.1.2
2 parents 6657054 + d776399 commit 230e46c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1001
-535
lines changed

Godeps/Godeps.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

+10-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ GOFMT_CMD := gofmt -s -l
2626
GOVET_CMD := go tool vet
2727
CI_HOST_TARGETS ?= "host-unit-test host-integ-test host-build-docker-image"
2828
SYSTEM_TESTS_TO_RUN ?= "00SSH|Basic|Network|Policy|TestTrigger|ACIM|Netprofile"
29+
ACI_GW_IMAGE ?= "contiv/aci-gw:04-12-2017.2.2_1n"
2930

3031
all: build unit-test system-test ubuntu-tests
3132

@@ -232,10 +233,16 @@ l3-test:
232233
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./createcfg.py -contiv_l3 2
233234
CONTIV_L3=2 CONTIV_NODES=3 go test -v -timeout 900m ./test/systemtests -check.v -check.abort
234235
CONTIV_L3=2 CONTIV_NODES=3 make stop
235-
l3-demo:
236+
237+
#l3-demo setup for docker/swarm
238+
l3-demo: demo
239+
vagrant ssh netplugin-node1 -c 'netctl global set --fwd-mode routing'
240+
241+
l3bgp-demo:
236242
CONTIV_L3=1 CONTIV_NODES=3 vagrant up
237243
make ssh-build
238244
vagrant ssh netplugin-node1 -c 'sudo -i bash -lc "cd /opt/gopath/src/github.com/contiv/netplugin && make host-restart"'
245+
vagrant ssh netplugin-node1 -c 'sh /opt/gopath/src/github.com/contiv/netplugin/scripts/l3bgp_demo.sh'
239246

240247
host-build:
241248
@echo "dev: making binaries..."
@@ -262,8 +269,8 @@ host-integ-test: host-cleanup start-aci-gw
262269

263270
start-aci-gw:
264271
@echo dev: starting aci gw...
265-
docker pull contiv/aci-gw:04-12-2017.2.2_1n
266-
docker run --net=host -itd -e "APIC_URL=SANITY" -e "APIC_USERNAME=IGNORE" -e "APIC_PASSWORD=IGNORE" --name=contiv-aci-gw contiv/aci-gw:04-12-2017.2.2_1n
272+
docker pull $(ACI_GW_IMAGE)
273+
docker run --net=host -itd -e "APIC_URL=SANITY" -e "APIC_USERNAME=IGNORE" -e "APIC_PASSWORD=IGNORE" --name=contiv-aci-gw $(ACI_GW_IMAGE)
267274

268275
host-build-docker-image:
269276
./scripts/netContain/build_image.sh

core/core.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ type NetworkDriver interface {
113113
Init(instInfo *InstanceInfo) error
114114
Deinit()
115115
CreateNetwork(id string) error
116-
DeleteNetwork(id, nwType, encap string, pktTag, extPktTag int, gateway string, tenant string) error
116+
DeleteNetwork(id, subnet, nwType, encap string, pktTag, extPktTag int, gateway string, tenant string) error
117117
CreateEndpoint(id string) error
118118
UpdateEndpointGroup(id string) error
119119
DeleteEndpoint(id string) error

drivers/driverconstants.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package drivers
2+
3+
import "github.com/contiv/netplugin/netmaster/mastercfg"
4+
5+
const (
6+
// StateOperPath is the path to the operations stored in state.
7+
networkOperPathPrefix = mastercfg.StateOperPath + "nets/"
8+
networkOperPath = networkOperPathPrefix + "%s"
9+
endpointOperPathPrefix = mastercfg.StateOperPath + "eps/"
10+
endpointOperPath = endpointOperPathPrefix + "%s"
11+
)

drivers/ovsendpointstate.go drivers/endpointstate.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"github.com/contiv/netplugin/netmaster/mastercfg"
2424
)
2525

26-
// OvsOperEndpointState is the necessary data used to perform operations on endpoints.
27-
type OvsOperEndpointState struct {
26+
// OperEndpointState is the necessary data used to perform operations on endpoints.
27+
type OperEndpointState struct {
2828
core.CommonState
2929
NetID string `json:"netID"`
3030
EndpointID string `json:"endpointID"`
@@ -39,7 +39,7 @@ type OvsOperEndpointState struct {
3939
}
4040

4141
// Matches matches the fields updated from configuration state
42-
func (s *OvsOperEndpointState) Matches(c *mastercfg.CfgEndpointState) bool {
42+
func (s *OperEndpointState) Matches(c *mastercfg.CfgEndpointState) bool {
4343
return s.NetID == c.NetID &&
4444
s.EndpointID == c.EndpointID &&
4545
s.IPAddress == c.IPAddress &&
@@ -50,24 +50,24 @@ func (s *OvsOperEndpointState) Matches(c *mastercfg.CfgEndpointState) bool {
5050
}
5151

5252
// Write the state.
53-
func (s *OvsOperEndpointState) Write() error {
53+
func (s *OperEndpointState) Write() error {
5454
key := fmt.Sprintf(endpointOperPath, s.ID)
5555
return s.StateDriver.WriteState(key, s, json.Marshal)
5656
}
5757

5858
// Read the state for a given identifier.
59-
func (s *OvsOperEndpointState) Read(id string) error {
59+
func (s *OperEndpointState) Read(id string) error {
6060
key := fmt.Sprintf(endpointOperPath, id)
6161
return s.StateDriver.ReadState(key, s, json.Unmarshal)
6262
}
6363

6464
// ReadAll reads all state into separate objects.
65-
func (s *OvsOperEndpointState) ReadAll() ([]core.State, error) {
65+
func (s *OperEndpointState) ReadAll() ([]core.State, error) {
6666
return s.StateDriver.ReadAllState(endpointOperPathPrefix, s, json.Unmarshal)
6767
}
6868

6969
// Clear removes the state.
70-
func (s *OvsOperEndpointState) Clear() error {
70+
func (s *OperEndpointState) Clear() error {
7171
key := fmt.Sprintf(endpointOperPath, s.ID)
7272
return s.StateDriver.ClearState(key)
7373
}

drivers/ovsendpointstate_test.go drivers/endpointstate_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ func (d *testEpStateDriver) WriteState(key string, value core.State,
8686
return d.validateKey(key)
8787
}
8888

89-
func TestOvsOperEndpointStateRead(t *testing.T) {
90-
epOper := &OvsOperEndpointState{}
89+
func TestOperEndpointStateRead(t *testing.T) {
90+
epOper := &OperEndpointState{}
9191
epOper.StateDriver = epStateDriver
9292

9393
err := epOper.Read(testEpID)
@@ -96,8 +96,8 @@ func TestOvsOperEndpointStateRead(t *testing.T) {
9696
}
9797
}
9898

99-
func TestOvsOperEndpointStateWrite(t *testing.T) {
100-
epOper := &OvsOperEndpointState{}
99+
func TestOperEndpointStateWrite(t *testing.T) {
100+
epOper := &OperEndpointState{}
101101
epOper.StateDriver = epStateDriver
102102
epOper.ID = testEpID
103103

@@ -107,8 +107,8 @@ func TestOvsOperEndpointStateWrite(t *testing.T) {
107107
}
108108
}
109109

110-
func TestOvsOperEndpointStateClear(t *testing.T) {
111-
epOper := &OvsOperEndpointState{}
110+
func TestOperEndpointStateClear(t *testing.T) {
111+
epOper := &OperEndpointState{}
112112
epOper.StateDriver = epStateDriver
113113
epOper.ID = testEpID
114114

drivers/fakenetepdriver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (d *FakeNetEpDriver) CreateNetwork(id string) error {
2626
}
2727

2828
// DeleteNetwork is not implemented.
29-
func (d *FakeNetEpDriver) DeleteNetwork(id, nwType, encap string, pktTag, extPktTag int, gateway string, tenant string) error {
29+
func (d *FakeNetEpDriver) DeleteNetwork(id, subnet, nwType, encap string, pktTag, extPktTag int, gateway string, tenant string) error {
3030
return core.Errorf("Not implemented")
3131
}
3232

drivers/nodeProxy.go drivers/ovsd/nodeProxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
1515

16-
package drivers
16+
package ovsd
1717

1818
import (
1919
"fmt"

drivers/nodeProxy_test.go drivers/ovsd/nodeProxy_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
1515

16-
package drivers
16+
package ovsd
1717

1818
import (
1919
"fmt"
2020
osexec "os/exec"
2121
"testing"
2222

2323
"github.com/contiv/netplugin/core"
24+
"github.com/contiv/netplugin/state"
2425
)
2526

2627
var ipTablesPath string

drivers/ovsSwitch.go drivers/ovsd/ovsSwitch.go

+24-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
1515

16-
package drivers
16+
package ovsd
1717

1818
import (
1919
"errors"
@@ -26,6 +26,7 @@ import (
2626
"time"
2727

2828
"github.com/contiv/netplugin/core"
29+
"github.com/contiv/netplugin/drivers"
2930
"github.com/contiv/netplugin/netmaster/mastercfg"
3031
"github.com/contiv/netplugin/utils/netutils"
3132
"github.com/contiv/ofnet"
@@ -482,7 +483,7 @@ func (sw *OvsSwitch) UpdatePort(intfName string, cfgEp *mastercfg.CfgEndpointSta
482483
}
483484

484485
// DeletePort removes a port from OVS
485-
func (sw *OvsSwitch) DeletePort(epOper *OvsOperEndpointState, skipVethPair bool) error {
486+
func (sw *OvsSwitch) DeletePort(epOper *drivers.OperEndpointState, skipVethPair bool) error {
486487

487488
if epOper.VtepIP != "" {
488489
return nil
@@ -491,20 +492,28 @@ func (sw *OvsSwitch) DeletePort(epOper *OvsOperEndpointState, skipVethPair bool)
491492
// Get the OVS port name
492493
ovsPortName := getOvsPortName(epOper.PortName, skipVethPair)
493494

494-
// Get the openflow port number for the interface
495+
// Get the openflow port number for the interface and remove from ofnet
495496
ofpPort, err := sw.ovsdbDriver.GetOfpPortNo(ovsPortName)
496-
if err != nil {
497-
log.Errorf("Could not find the OVS port %s. Err: %v", ovsPortName, err)
498-
return err
499-
}
500-
501-
// Remove info from ofnet
502-
if sw.ofnetAgent != nil {
503-
err = sw.ofnetAgent.RemoveLocalEndpoint(ofpPort)
504-
if err != nil {
505-
log.Errorf("Error removing port %s from ofnet. Err: %v", ovsPortName, err)
506-
// continue with further cleanup
497+
if err == nil {
498+
if sw.ofnetAgent != nil {
499+
err = sw.ofnetAgent.RemoveLocalEndpoint(ofpPort)
507500
}
501+
} else {
502+
if sw.ofnetAgent != nil {
503+
var tenantName string
504+
netParts := strings.Split(epOper.NetID, ".")
505+
if len(netParts) == 2 {
506+
tenantName = netParts[1]
507+
} else {
508+
tenantName = "default"
509+
}
510+
epID := sw.ofnetAgent.GetEndpointIdByIpVrf(net.ParseIP(epOper.IPAddress), tenantName)
511+
err = sw.ofnetAgent.RemoveLocalEndpointByID(epID)
512+
}
513+
}
514+
if err != nil {
515+
log.Errorf("Error removing endpoint %+v from ofnet. Err: %v", epOper, err)
516+
// continue with further cleanup
508517
}
509518

510519
// Delete it from ovsdb
@@ -519,7 +528,7 @@ func (sw *OvsSwitch) DeletePort(epOper *OvsOperEndpointState, skipVethPair bool)
519528
// Delete a Veth pair
520529
verr := deleteVethPair(ovsPortName, epOper.PortName)
521530
if verr != nil {
522-
log.Errorf("Error creating veth pairs. Err: %v", verr)
531+
log.Errorf("Error deleting veth pairs. Err: %v", verr)
523532
return verr
524533
}
525534
}

drivers/ovsconstants.go drivers/ovsd/ovsconstants.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
package drivers
1+
package ovsd
22

3-
import "github.com/contiv/netplugin/netmaster/mastercfg"
3+
import (
4+
"github.com/contiv/netplugin/netmaster/mastercfg"
5+
)
46

57
const (
68
operCreateBridge oper = iota
@@ -23,10 +25,6 @@ const (
2325
hostPvtSubnet = "172.20.0.0/16"
2426

2527
// StateOperPath is the path to the operations stored in state.
26-
ovsOperPathPrefix = mastercfg.StateOperPath + "ovs-driver/"
27-
ovsOperPath = ovsOperPathPrefix + "%s"
28-
networkOperPathPrefix = mastercfg.StateOperPath + "nets/"
29-
endpointOperPathPrefix = mastercfg.StateOperPath + "eps/"
30-
networkOperPath = networkOperPathPrefix + "%s"
31-
endpointOperPath = endpointOperPathPrefix + "%s"
28+
ovsOperPathPrefix = mastercfg.StateOperPath + "ovs-driver/"
29+
ovsOperPath = ovsOperPathPrefix + "%s"
3230
)

drivers/ovsdbDriver.go drivers/ovsd/ovsdbDriver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
1515

16-
package drivers
16+
package ovsd
1717

1818
import (
1919
"errors"

drivers/ovsdriver.go drivers/ovsd/ovsdriver.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
1515

16-
package drivers
16+
package ovsd
1717

1818
import (
1919
"encoding/json"
@@ -26,6 +26,7 @@ import (
2626

2727
log "github.com/Sirupsen/logrus"
2828
"github.com/contiv/netplugin/core"
29+
"github.com/contiv/netplugin/drivers"
2930
"github.com/contiv/netplugin/netmaster/mastercfg"
3031
"github.com/contiv/netplugin/netplugin/nameserver"
3132
"github.com/contiv/netplugin/utils/netutils"
@@ -220,7 +221,7 @@ func (d *OvsDriver) Init(info *core.InstanceInfo) error {
220221
func (d *OvsDriver) DeleteHostAccPort(id string) error {
221222
sw, found := d.switchDb["host"]
222223
if found {
223-
operEp := &OvsOperEndpointState{}
224+
operEp := &drivers.OperEndpointState{}
224225
operEp.StateDriver = d.oper.StateDriver
225226
err := operEp.Read(id)
226227
if err != nil {
@@ -293,7 +294,7 @@ func (d *OvsDriver) CreateNetwork(id string) error {
293294
}
294295

295296
// DeleteNetwork deletes a network by named identifier
296-
func (d *OvsDriver) DeleteNetwork(id, nwType, encap string, pktTag, extPktTag int, gateway string, tenant string) error {
297+
func (d *OvsDriver) DeleteNetwork(id, subnet, nwType, encap string, pktTag, extPktTag int, gateway string, tenant string) error {
297298
log.Infof("delete net %s, nwType %s, encap %s, tags: %d/%d", id, nwType, encap, pktTag, extPktTag)
298299

299300
// Find the switch based on network type
@@ -309,7 +310,7 @@ func (d *OvsDriver) DeleteNetwork(id, nwType, encap string, pktTag, extPktTag in
309310
hostName, _ := os.Hostname()
310311
epID := id + "-" + hostName
311312

312-
epOper := OvsOperEndpointState{}
313+
epOper := drivers.OperEndpointState{}
313314
epOper.StateDriver = d.oper.StateDriver
314315
err := epOper.Read(epID)
315316
if err == nil {
@@ -386,7 +387,7 @@ func (d *OvsDriver) CreateEndpoint(id string) error {
386387
// Skip Veth pair creation for infra nw endpoints
387388
skipVethPair := (cfgNw.NwType == "infra")
388389

389-
operEp := &OvsOperEndpointState{}
390+
operEp := &drivers.OperEndpointState{}
390391
operEp.StateDriver = d.oper.StateDriver
391392
err = operEp.Read(id)
392393
if core.ErrIfKeyExists(err) != nil {
@@ -445,7 +446,7 @@ func (d *OvsDriver) CreateEndpoint(id string) error {
445446
return err
446447
}
447448
// Save the oper state
448-
operEp = &OvsOperEndpointState{
449+
operEp = &drivers.OperEndpointState{
449450
NetID: cfgEp.NetID,
450451
EndpointID: cfgEp.EndpointID,
451452
ServiceName: cfgEp.ServiceName,
@@ -517,7 +518,7 @@ func (d *OvsDriver) UpdateEndpointGroup(id string) error {
517518

518519
// DeleteEndpoint deletes an endpoint by named identifier.
519520
func (d *OvsDriver) DeleteEndpoint(id string) error {
520-
epOper := OvsOperEndpointState{}
521+
epOper := drivers.OperEndpointState{}
521522
epOper.StateDriver = d.oper.StateDriver
522523
err := epOper.Read(id)
523524
if err != nil {
@@ -552,6 +553,10 @@ func (d *OvsDriver) DeleteEndpoint(id string) error {
552553
d.oper.localEpInfoMutex.Lock()
553554
delete(d.oper.LocalEpInfo, id)
554555
d.oper.localEpInfoMutex.Unlock()
556+
err = d.oper.Write()
557+
if err != nil {
558+
return err
559+
}
555560

556561
return nil
557562
}

0 commit comments

Comments
 (0)