// Create a new network using bridge plugin
338587
func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
	if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" {
		return types.BadRequestErrorf("ipv4 pool is empty")
	}
	// Sanity checks
	d.Lock()
	if _, ok := d.networks[id]; ok {
		d.Unlock()
		return types.ForbiddenErrorf("network %s exists", id)
	}
	d.Unlock()

	// Parse and validate the config. It should not be conflict with existing networks' config
	config, err := parseNetworkOptions(id, option)
	if err != nil {
		return err
	}

	if err = config.processIPAM(id, ipV4Data, ipV6Data); err != nil {
		return err
	}

	// start the critical section, from this point onward we are dealing with the list of networks
	// so to be consistent we cannot allow that the list changes
	d.configNetwork.Lock()
	defer d.configNetwork.Unlock()

	// check network conflicts
	if err = d.checkConflict(config); err != nil {
		nerr, ok := err.(defaultBridgeNetworkConflict)
		if !ok {
			return err
		}
		// Got a conflict with a stale default network, clean that up and continue
		logrus.Warn(nerr)
		d.deleteNetwork(nerr.ID)
	}

	// there is no conflict, now create the network
	if err = d.createNetwork(config); err != nil {
		return err
	}

	return d.storeUpdate(config)
}
440053
func (s *NetworkACLService) NewCreateNetworkACLParams(protocol string) *CreateNetworkACLParams {
	p := &CreateNetworkACLParams{}
	p.p = make(map[string]interface{})
	p.p["protocol"] = protocol
	return p
}
772513
func (c *Client) CreateNetworkOffering(p *CreateNetworkOfferingParameter) (*NetworkOffering, error) {
	obj, err := c.Request("createNetworkOffering", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*NetworkOffering), err
}
1307833
func (d *OvsDriver) CreateNetwork(id string) error {
	cfgNw := mastercfg.CfgNetworkState{}
	cfgNw.StateDriver = d.oper.StateDriver
	err := cfgNw.Read(id)
	if err != nil {
		log.Errorf("Failed to read net %s \n", cfgNw.ID)
		return err
	}
	log.Infof("create net %+v \n", cfgNw)

	// Find the switch based on network type
	var sw *OvsSwitch
	if cfgNw.PktTagType == "vxlan" {
		sw = d.switchDb["vxlan"]
	} else {
		sw = d.switchDb["vlan"]
	}

	return sw.CreateNetwork(uint16(cfgNw.PktTag), uint32(cfgNw.ExtPktTag), cfgNw.Gateway, cfgNw.Tenant)
}
144232
func newCreateClientTunnelReply(cidr *net.IPNet, tid int64) (f linkFrame) {
  f.method = CLIENT_TUN_NEW
  f.param = map[string]interface{} { K_CIDR : cidr.String() }
  f.response = tid
  return
}
46319
func NewBridge(ip string) (*Bridge, error) {
	bridge := Bridge{
		IPAddress: ip,
	}
	// Test the connection by attempting to get the bridge info.
	err := bridge.GetInfo()
	if err != nil {
		return &Bridge{}, err
	}
	return &bridge, nil
}
1227371
func (api *NetworksAPI) CreateSubnet(networkID string, spec *SubnetCreateSpec) (task *Task, err error) {
	body, err := json.Marshal(spec)
	if err != nil {
		return
	}
	res, err := api.client.restClient.Post(
		api.client.Endpoint+networkUrl+networkID+"/subnets",
		"application/json",
		bytes.NewReader(body),
		api.client.options.TokenOptions)
	if err != nil {
		return
	}
	defer res.Body.Close()
	task, err = getTask(getError(res))
	return
}
633070
func NewNetworkCli(out, err io.Writer, call CallFunc) *NetworkCli {
	return &NetworkCli{
		out:  out,
		err:  err,
		call: call,
	}
}
133954
func CreateNetwork(network intent.ConfigNetwork, stateDriver core.StateDriver, tenantName string) error {
	var extPktTag, pktTag uint

	gstate.GlobalMutex.Lock()
	defer gstate.GlobalMutex.Unlock()
	gCfg := gstate.Cfg{}
	gCfg.StateDriver = stateDriver
	err := gCfg.Read("")
	if err != nil {
		log.Errorf("error reading tenant cfg state. Error: %s", err)
		return err
	}

	// Create network state
	networkID := network.Name + "." + tenantName
	nwCfg := &mastercfg.CfgNetworkState{}
	nwCfg.StateDriver = stateDriver
	if nwCfg.Read(networkID) == nil {
		// TODO: check if parameters changed and apply an update if needed
		return nil
	}

	subnetIP, subnetLen, _ := netutils.ParseCIDR(network.SubnetCIDR)
	err = netutils.ValidateNetworkRangeParams(subnetIP, subnetLen)
	if err != nil {
		return err
	}

	ipv6Subnet, ipv6SubnetLen, _ := netutils.ParseCIDR(network.IPv6SubnetCIDR)

	// if there is no label given generate one for the network
	nwTag := network.CfgdTag
	if nwTag == "" {
		nwTag = network.Name + "." + tenantName
	}

	// construct and update network state
	nwCfg = &mastercfg.CfgNetworkState{
		Tenant:        tenantName,
		NetworkName:   network.Name,
		NwType:        network.NwType,
		PktTagType:    network.PktTagType,
		SubnetIP:      subnetIP,
		SubnetLen:     subnetLen,
		IPv6Subnet:    ipv6Subnet,
		IPv6SubnetLen: ipv6SubnetLen,
		NetworkTag:    nwTag,
	}

	nwCfg.ID = networkID
	nwCfg.StateDriver = stateDriver

	netutils.InitSubnetBitset(&nwCfg.IPAllocMap, nwCfg.SubnetLen)
	subnetAddr := netutils.GetSubnetAddr(nwCfg.SubnetIP, nwCfg.SubnetLen)
	nwCfg.SubnetIP = subnetAddr
	nwCfg.IPAddrRange = netutils.GetIPAddrRange(subnetIP, subnetLen)

	if network.Gateway != "" {
		nwCfg.Gateway = network.Gateway

		// Reserve gateway IP address if gateway is specified
		ipAddrValue, err := netutils.GetIPNumber(subnetAddr, nwCfg.SubnetLen, 32, nwCfg.Gateway)
		if err != nil {
			log.Errorf("Error parsing gateway address %s. Err: %v", nwCfg.Gateway, err)
			return err
		}
		nwCfg.IPAllocMap.Set(ipAddrValue)
	}

	if strings.Contains(subnetIP, "-") {
		netutils.SetBitsOutsideRange(&nwCfg.IPAllocMap, subnetIP, subnetLen)
	}

	if network.IPv6Gateway != "" {
		nwCfg.IPv6Gateway = network.IPv6Gateway

		// Reserve gateway IPv6 address if gateway is specified
		hostID, err := netutils.GetIPv6HostID(nwCfg.IPv6Subnet, nwCfg.IPv6SubnetLen, nwCfg.IPv6Gateway)
		if err != nil {
			log.Errorf("Error parsing gateway address %s. Err: %v", nwCfg.IPv6Gateway, err)
			return err
		}
		netutils.ReserveIPv6HostID(hostID, &nwCfg.IPv6AllocMap)
	}

	// Allocate pkt tags
	reqPktTag := uint(network.PktTag)
	if nwCfg.PktTagType == "vlan" {
		pktTag, err = gCfg.AllocVLAN(reqPktTag)
		if err != nil {
			return err
		}
	} else if nwCfg.PktTagType == "vxlan" {
		extPktTag, pktTag, err = gCfg.AllocVXLAN(reqPktTag)
		if err != nil {
			return err
		}
	}

	nwCfg.ExtPktTag = int(extPktTag)
	nwCfg.PktTag = int(pktTag)

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

	// Skip docker and service container configs for infra nw
	if network.NwType == "infra" {
		return nil
	}

	aci, _ := IsAciConfigured()
	if aci {
		// Skip docker network creation for ACI fabric mode.
		return nil
	}

	if GetClusterMode() == core.Docker {
		// Create the network in docker
		err = docknet.CreateDockNet(tenantName, network.Name, "", nwCfg)
		if err != nil {
			log.Errorf("Error creating network %s in docker. Err: %v", nwCfg.ID, err)
			return err
		}
	}

	return nil
}
197132
func (s *NetworkService) CreateNetwork(p *CreateNetworkParams) (*CreateNetworkResponse, error) {
	resp, err := s.cs.newRequest("createNetwork", p.toURLValues())
	if err != nil {
		return nil, err
	}

	if resp, err = getRawValue(resp); err != nil {
		return nil, err
	}

	var r CreateNetworkResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
967989
func (p *proxy_PerHost) AddNetwork(net *net.IPNet) {
	p.bypassNetworks = append(p.bypassNetworks, net)
}
633569
func DefaultNetplanBridger(timeout time.Duration, directory string) (Bridger, error) {
	return newNetplanBridger(clock.WallClock, timeout, directory), nil
}
596335
func (s *Stack) CreateNIC(id tcpip.NICID, linkEP tcpip.LinkEndpointID) *tcpip.Error {
	return s.createNIC(id, "", linkEP, true, false)
}
1234748
func (o *VPort) CreateBridgeInterface(child *BridgeInterface) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
1105725
func (nDB *NetworkDB) addNetworkNode(nid string, nodeName string) {
	nodes := nDB.networkNodes[nid]
	for _, node := range nodes {
		if node == nodeName {
			return
		}
	}

	nDB.networkNodes[nid] = append(nDB.networkNodes[nid], nodeName)
}
822381
func (s *NetworkACLService) CreateNetworkACL(p *CreateNetworkACLParams) (*CreateNetworkACLResponse, error) {
	resp, err := s.cs.newRequest("createNetworkACL", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r CreateNetworkACLResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		b, err = getRawValue(b)
		if err != nil {
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
1075983
func NewNetwork(projectName, name string, config *config.NetworkConfig, client client.NetworkAPIClient) *Network {
	networkName := name
	if config.External.External {
		networkName = config.External.Name
	}
	return &Network{
		client:        client,
		name:          networkName,
		projectName:   projectName,
		driver:        config.Driver,
		driverOptions: config.DriverOpts,
		external:      config.External.External,
		ipam:          config.Ipam,
	}
}