예제 #1
0
파일: netd.go 프로젝트: shwethab/netplugin
func handleEndpointEvents(netPlugin *plugin.NetPlugin, crt *crt.CRT,
	opts cliOpts, retErr chan error) {
	rsps := make(chan core.WatchState)
	go processStateEvent(netPlugin, crt, opts, rsps)
	cfg := drivers.OvsCfgEndpointState{}
	cfg.StateDriver = netPlugin.StateDriver
	retErr <- cfg.WatchAll(rsps)
	return
}
예제 #2
0
func allocSetEpAddress(ep *intent.ConfigEP, epCfg *drivers.OvsCfgEndpointState,
	nwCfg *drivers.OvsCfgNetworkState) (err error) {

	var ipAddrValue uint
	var found bool

	ipAddress := ep.IPAddress
	if ipAddress == "" {
		if ipAddrValue, found = nwCfg.IPAllocMap.NextClear(0); !found {
			log.Errorf("auto allocation failed - address exhaustion in subnet %s/%d",
				nwCfg.SubnetIP, nwCfg.SubnetLen)
			err = core.Errorf("auto allocation failed - address exhaustion in subnet %s/%d",
				nwCfg.SubnetIP, nwCfg.SubnetLen)
			return
		}
		ipAddress, err = netutils.GetSubnetIP(
			nwCfg.SubnetIP, nwCfg.SubnetLen, 32, ipAddrValue)
		if err != nil {
			log.Errorf("create eps: error acquiring subnet ip. Error: %s", err)
			return
		}
	} else if ipAddress != "" && nwCfg.SubnetIP != "" {
		ipAddrValue, err = netutils.GetIPNumber(
			nwCfg.SubnetIP, nwCfg.SubnetLen, 32, ipAddress)
		if err != nil {
			log.Errorf("create eps: error getting host id from hostIP %s Subnet %s/%d. Error: %s",
				ipAddress, nwCfg.SubnetIP, nwCfg.SubnetLen, err)
			return
		}
	}
	epCfg.IPAddress = ipAddress
	nwCfg.IPAllocMap.Set(ipAddrValue)

	// Set mac address which is derived from IP address
	ipAddr := net.ParseIP(ipAddress)
	macAddr := fmt.Sprintf("02:02:%02x:%02x:%02x:%02x", ipAddr[12], ipAddr[13], ipAddr[14], ipAddr[15])
	epCfg.MacAddress = macAddr

	return
}
예제 #3
0
func createInfraNetwork(epCfg *drivers.OvsCfgEndpointState) error {
	if epCfg.NetID != "" {
		return nil
	}

	nwCfg := &drivers.OvsCfgNetworkState{}
	nwCfg.StateDriver = epCfg.StateDriver
	if nwCfg.Read(epCfg.NetID) == nil {
		return nil
	}

	nwCfg.ID = defaultInfraNetName
	err := nwCfg.Write()
	if err != nil {
		return err
	}

	epCfg.NetID = defaultInfraNetName
	return nil
}