// CreateVtep creates a VTEP port on the OVS func (d *OvsdbDriver) CreateVtep(intfName string, vtepRemoteIP string) error { portUUIDStr := intfName intfUUIDStr := fmt.Sprintf("Intf%s", intfName) portUUID := []libovsdb.UUID{{portUUIDStr}} intfUUID := []libovsdb.UUID{{intfUUIDStr}} opStr := "insert" intfType := "vxlan" var err error // insert/delete a row in Interface table intf := make(map[string]interface{}) intf["name"] = intfName intf["type"] = intfType // Special handling for VTEP ports intfOptions := make(map[string]interface{}) intfOptions["remote_ip"] = vtepRemoteIP intfOptions["key"] = "flow" // Insert VNI per flow intf["options"], err = libovsdb.NewOvsMap(intfOptions) if err != nil { log.Errorf("error '%s' creating options from %v \n", err, intfOptions) return err } // Add an entry in Interface table intfOp := libovsdb.Operation{ Op: opStr, Table: interfaceTable, Row: intf, UUIDName: intfUUIDStr, } // insert/delete a row in Port table port := make(map[string]interface{}) port["name"] = intfName port["vlan_mode"] = "trunk" port["interfaces"], err = libovsdb.NewOvsSet(intfUUID) if err != nil { return err } // Add an entry in Port table portOp := libovsdb.Operation{ Op: opStr, Table: portTable, Row: port, UUIDName: portUUIDStr, } // mutate the Ports column of the row in the Bridge table mutateSet, _ := libovsdb.NewOvsSet(portUUID) mutation := libovsdb.NewMutation("ports", opStr, mutateSet) condition := libovsdb.NewCondition("name", "==", d.bridgeName) mutateOp := libovsdb.Operation{ Op: "mutate", Table: bridgeTable, Mutations: []interface{}{mutation}, Where: []interface{}{condition}, } // Perform OVS transaction operations := []libovsdb.Operation{intfOp, portOp, mutateOp} return d.performOvsdbOps(operations) }
// CreatePort creates an OVS port func (d *OvsdbDriver) CreatePort(intfName, intfType, id string, tag int) error { // intfName is assumed to be unique enough to become uuid portUUIDStr := intfName intfUUIDStr := fmt.Sprintf("Intf%s", intfName) portUUID := []libovsdb.UUID{libovsdb.UUID{GoUuid: portUUIDStr}} intfUUID := []libovsdb.UUID{libovsdb.UUID{GoUuid: intfUUIDStr}} opStr := "insert" var err error // insert/delete a row in Interface table idMap := make(map[string]string) intfOp := libovsdb.Operation{} intf := make(map[string]interface{}) intf["name"] = intfName intf["type"] = intfType idMap["endpoint-id"] = id intf["external_ids"], err = libovsdb.NewOvsMap(idMap) if err != nil { return err } // interface table ops intfOp = libovsdb.Operation{ Op: opStr, Table: interfaceTable, Row: intf, UUIDName: intfUUIDStr, } // insert/delete a row in Port table portOp := libovsdb.Operation{} port := make(map[string]interface{}) port["name"] = intfName if tag != 0 { port["vlan_mode"] = "access" port["tag"] = tag } else { port["vlan_mode"] = "trunk" } port["interfaces"], err = libovsdb.NewOvsSet(intfUUID) if err != nil { return err } port["external_ids"], err = libovsdb.NewOvsMap(idMap) if err != nil { return err } portOp = libovsdb.Operation{ Op: opStr, Table: portTable, Row: port, UUIDName: portUUIDStr, } // mutate the Ports column of the row in the Bridge table mutateSet, _ := libovsdb.NewOvsSet(portUUID) mutation := libovsdb.NewMutation("ports", opStr, mutateSet) condition := libovsdb.NewCondition("name", "==", d.bridgeName) mutateOp := libovsdb.Operation{ Op: "mutate", Table: bridgeTable, Mutations: []interface{}{mutation}, Where: []interface{}{condition}, } operations := []libovsdb.Operation{intfOp, portOp, mutateOp} return d.performOvsdbOps(operations) }