// AddBridge creates the bridge associated with the transaction, optionally setting
// properties on it (as with "ovs-vsctl set Bridge ..."). If the bridge already
// existed, it will be destroyed and recreated.
431928
func (tx *Transaction) AddBridge(properties ...string) {
	args := []string{"--if-exists", "del-br", tx.bridge, "--", "add-br", tx.bridge}
	if len(properties) > 0 {
		args = append(args, "--", "set", "Bridge", tx.bridge)
		args = append(args, properties...)
	}
	tx.vsctlExec(args...)
}
1110982
func (tx *Transaction) AddPort(port string, ofport uint, properties ...string) {
	args := []string{"--if-exists", "del-port", port, "--", "add-port", tx.bridge, port, "--", "set", "Interface", port, fmt.Sprintf("ofport_request=%d", ofport)}
	if len(properties) > 0 {
		args = append(args, properties...)
	}
	tx.vsctlExec(args...)
}
1234748
func (o *VPort) CreateBridgeInterface(child *BridgeInterface) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
1054852
func NewOvsSwitch(bridgeName, netType, localIP, fwdMode string,
	vlanIntf []string, hostPvtNW int, vxlanUDPPort int) (*OvsSwitch, error) {
	var err error
	var datapath string
	var ofnetPort, ctrlrPort uint16
	log.Infof("Received request to create new ovs switch bridge:%s, localIP:%s, fwdMode:%s", bridgeName, localIP, fwdMode)
	sw := new(OvsSwitch)
	sw.bridgeName = bridgeName
	sw.netType = netType
	sw.uplinkDb = cmap.New()
	sw.hostPvtNW = hostPvtNW
	sw.vxlanEncapMtu, err = netutils.GetHostLowestLinkMtu()
	if err != nil {
		log.Fatalf("Failed to get Host Node MTU. Err: %v", err)
	}

	// Create OVS db driver
	sw.ovsdbDriver, err = NewOvsdbDriver(bridgeName, "secure", vxlanUDPPort)
	if err != nil {
		log.Fatalf("Error creating ovsdb driver. Err: %v", err)
	}

	sw.ovsdbDriver.ovsSwitch = sw

	if netType == "vxlan" {
		ofnetPort = vxlanOfnetPort
		ctrlrPort = vxlanCtrlerPort
		switch fwdMode {
		case "bridge":
			datapath = "vxlan"
		case "routing":
			datapath = "vrouter"
		default:
			log.Errorf("Invalid datapath mode")
			return nil, errors.New("invalid forwarding mode. Expects 'bridge' or 'routing'")
		}
		// Create an ofnet agent
		sw.ofnetAgent, err = ofnet.NewOfnetAgent(bridgeName, datapath, net.ParseIP(localIP),
			ofnetPort, ctrlrPort, vlanIntf)

		if err != nil {
			log.Fatalf("Error initializing ofnet")
			return nil, err
		}

	} else if netType == "vlan" {
		ofnetPort = vlanOfnetPort
		ctrlrPort = vlanCtrlerPort
		switch fwdMode {
		case "bridge":
			datapath = "vlan"
		case "routing":
			datapath = "vlrouter"
		default:
			log.Errorf("Invalid datapath mode")
			return nil, errors.New("invalid forwarding mode. Expects 'bridge' or 'routing'")
		}
		// Create an ofnet agent
		sw.ofnetAgent, err = ofnet.NewOfnetAgent(bridgeName, datapath, net.ParseIP(localIP),
			ofnetPort, ctrlrPort, vlanIntf)

		if err != nil {
			log.Fatalf("Error initializing ofnet")
			return nil, err
		}

	} else if netType == "host" {
		err = fmt.Errorf("Explicit host-net not supported")
		return nil, err
	}

	// Add controller to the OVS
	ctrlerIP := "127.0.0.1"
	target := fmt.Sprintf("tcp:%s:%d", ctrlerIP, ctrlrPort)
	if !sw.ovsdbDriver.IsControllerPresent(target) {
		err = sw.ovsdbDriver.AddController(ctrlerIP, ctrlrPort)
		if err != nil {
			log.Errorf("Error adding controller to switch: %s. Err: %v", bridgeName, err)
			return nil, err
		}
	}

	log.Infof("Waiting for OVS switch(%s) to connect..", netType)

	// Wait for a while for OVS switch to connect to agent
	if sw.ofnetAgent != nil {
		sw.ofnetAgent.WaitForSwitchConnection()
	}

	log.Infof("Switch (%s) connected.", netType)

	return sw, nil
}
1239280
func (bv *Values) AddOnce(value interface{}) bool {
	return bv.addIfNotExists(reflect.ValueOf(value))
}
1292883
func (np *Netplan) shouldCreateBridge(deviceId string, bridgeName string) (bool, error) {
	for bName, bridge := range np.Network.Bridges {
		for _, i := range bridge.Interfaces {
			if i == deviceId {
				// The device is already properly bridged, nothing to do
				if bridgeName == bName {
					return false, nil
				} else {
					return false, errors.AlreadyExistsf("cannot create bridge %q, device %q in bridge %q", bridgeName, deviceId, bName)
				}
			}
		}
		if bridgeName == bName {
			return false, errors.AlreadyExistsf(
				"cannot create bridge %q with device %q - bridge %q w/ interfaces %q",
				bridgeName, deviceId, bridgeName, strings.Join(bridge.Interfaces, ", "))
		}
	}
	return true, nil
}
1342305
func (s *SparkStream) Add(v float64) {
	s.l.Lock()
	s.cur += v
	s.l.Unlock()
}
648353
func (c *Connection) AddAlias(alias string, indexes []string) (*Response, error) {
	return c.modifyAlias("add", alias, indexes)
}
71266
func (a *Aliases) Add(alias, mac, iface string) error {
	a.mtx.Lock()
	defer a.mtx.Unlock()

	// Create a buffer to store the encoded MAC, interface pair.
	buf, err := EncodeFromMacIface(mac, iface)
	if err != nil {
		return err
	}

	// We don't have to worry about the key existing, as we will update it
	// provided it exists.
	return a.db.Update(func(tx *bolt.Tx) error {
		bucket := tx.Bucket([]byte(bucketName))
		return bucket.Put([]byte(alias), buf.Bytes())
	})
}
109466
func (conn *OCI8Conn) BeginTx(ctx context.Context, txOptions driver.TxOptions) (driver.Tx, error) {
	if conn.transactionMode != C.OCI_TRANS_READWRITE {
		// transaction handle
		trans, _, err := conn.ociHandleAlloc(C.OCI_HTYPE_TRANS, 0)
		if err != nil {
			return nil, fmt.Errorf("allocate transaction handle error: %v", err)
		}

		// sets the transaction context attribute of the service context
		err = conn.ociAttrSet(unsafe.Pointer(conn.svc), C.OCI_HTYPE_SVCCTX, *trans, 0, C.OCI_ATTR_TRANS)
		if err != nil {
			C.OCIHandleFree(*trans, C.OCI_HTYPE_TRANS)
			return nil, err
		}

		// transaction handle should be freed by something once attached to the service context
		// but I cannot find anything in the documentation explicitly calling this out
		// going by examples: https://docs.oracle.com/cd/B28359_01/appdev.111/b28395/oci17msc006.htm#i428845

		if rv := C.OCITransStart(
			conn.svc,
			conn.errHandle,
			0,
			conn.transactionMode, // mode is: C.OCI_TRANS_SERIALIZABLE, C.OCI_TRANS_READWRITE, or C.OCI_TRANS_READONLY
		); rv != C.OCI_SUCCESS {
			return nil, conn.getError(rv)
		}

	}

	conn.inTransaction = true

	return &OCI8Tx{conn}, nil
}
622063
func (v PreciseVector) Add(ov PreciseVector) PreciseVector {
	return PreciseVector{
		X: precAdd(v.X, ov.X),
		Y: precAdd(v.Y, ov.Y),
		Z: precAdd(v.Z, ov.Z),
	}
}
1224441
func (t *ObjectTree) Add(o Interface) (val interface{}, isDupe bool) {
	return t.Tree.Add(o)
}
134959
func (tx *Transaction) AddLink(args ...string) {
	tx.exec(append([]string{"link", "add", tx.link}, args...))
}
172620
func (c *Client) Add(data interface{}) error {
	c.ensureTransmission()
	c.ensureBuilder()
	return c.builder.Add(data)
}
376493
func (v1 Vec4) Add(v2 Vec4) Vec4 {
	return Vec4{v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2], v1[3] + v2[3]}
}
1201817
func (c *connectionTracker) AddConnection(conn net.Conn) {
	c.lock.Lock()
	defer c.lock.Unlock()
	c.conns[conn] = struct{}{}
}
1138821
func (c *Certificate) AddExtension(nid NID, value string) error {
	issuer := c
	if c.Issuer != nil {
		issuer = c.Issuer
	}
	var ctx C.X509V3_CTX
	C.X509V3_set_ctx(&ctx, c.x, issuer.x, nil, nil, 0)
	ex := C.X509V3_EXT_conf_nid(nil, &ctx, C.int(nid), C.CString(value))
	if ex == nil {
		return errors.New("failed to create x509v3 extension")
	}
	defer C.X509_EXTENSION_free(ex)
	if C.X509_add_ext(c.x, ex, -1) <= 0 {
		return errors.New("failed to add x509v3 extension")
	}
	return nil
}