Exemple #1
0
func TestCreateEndpoint(t *testing.T) {
	setup()
	defer teardown()

	req := &dnet.CreateEndpointRequest{}
	req.EndpointID = zero
	req.Interface = &dnet.EndpointInterface{
		MacAddress: "00:00:00:00:00:00",
	}

	d := driver{}
	_, err := d.CreateEndpoint(req)
	assert.NotNil(t, err)

	req.Interface.Address = "10.1.0.1"
	_, err = d.CreateEndpoint(req)
	assert.NotNil(t, err)

	req.Interface.Address = "10.1.0.1/8"
	req.Interface.MacAddress = ""
	expResp := dnet.EndpointInterface{
		MacAddress: ipdef.IPStrToMac("10.1.0.1"),
	}
	resp, err := d.CreateEndpoint(req)
	assert.Nil(t, err)
	assert.Equal(t, expResp, *resp.Interface)

	req.EndpointID = one
	req.Interface.Address = "10.1.0.2/8"
	expResp.MacAddress = ipdef.IPStrToMac("10.1.0.2")
	resp, err = d.CreateEndpoint(req)
	assert.Nil(t, err)
	assert.Equal(t, expResp, *resp.Interface)
}
Exemple #2
0
func updateLeaderDBC(view db.Database, dbcs []db.Container,
	etcdData storeData, ipMap map[string]string) {

	for _, dbc := range dbcs {
		ipVal := ipMap[strconv.Itoa(dbc.StitchID)]
		mac := ipdef.IPStrToMac(ipVal)
		if dbc.IP != ipVal || dbc.Mac != mac {
			dbc.IP = ipVal
			dbc.Mac = mac
			view.Commit(dbc)
		}
	}
}