github.com/rish1988/moby@v25.0.2+incompatible/libnetwork/driverapi/driverapi.go (about) 1 package driverapi 2 3 import "net" 4 5 // NetworkPluginEndpointType represents the Endpoint Type used by Plugin system 6 const NetworkPluginEndpointType = "NetworkDriver" 7 8 // Driver is an interface that every plugin driver needs to implement. 9 type Driver interface { 10 // NetworkAllocate invokes the driver method to allocate network 11 // specific resources passing network id and network specific config. 12 // It returns a key,value pair of network specific driver allocations 13 // to the caller. 14 NetworkAllocate(nid string, options map[string]string, ipV4Data, ipV6Data []IPAMData) (map[string]string, error) 15 16 // NetworkFree invokes the driver method to free network specific resources 17 // associated with a given network id. 18 NetworkFree(nid string) error 19 20 // CreateNetwork invokes the driver method to create a network 21 // passing the network id and network specific config. The 22 // config mechanism will eventually be replaced with labels 23 // which are yet to be introduced. The driver can return a 24 // list of table names for which it is interested in receiving 25 // notification when a CRUD operation is performed on any 26 // entry in that table. This will be ignored for local scope 27 // drivers. 28 CreateNetwork(nid string, options map[string]interface{}, nInfo NetworkInfo, ipV4Data, ipV6Data []IPAMData) error 29 30 // DeleteNetwork invokes the driver method to delete network passing 31 // the network id. 32 DeleteNetwork(nid string) error 33 34 // CreateEndpoint invokes the driver method to create an endpoint 35 // passing the network id, endpoint id endpoint information and driver 36 // specific config. The endpoint information can be either consumed by 37 // the driver or populated by the driver. The config mechanism will 38 // eventually be replaced with labels which are yet to be introduced. 39 CreateEndpoint(nid, eid string, ifInfo InterfaceInfo, options map[string]interface{}) error 40 41 // DeleteEndpoint invokes the driver method to delete an endpoint 42 // passing the network id and endpoint id. 43 DeleteEndpoint(nid, eid string) error 44 45 // EndpointOperInfo retrieves from the driver the operational data related to the specified endpoint 46 EndpointOperInfo(nid, eid string) (map[string]interface{}, error) 47 48 // Join method is invoked when a Sandbox is attached to an endpoint. 49 Join(nid, eid string, sboxKey string, jinfo JoinInfo, options map[string]interface{}) error 50 51 // Leave method is invoked when a Sandbox detaches from an endpoint. 52 Leave(nid, eid string) error 53 54 // ProgramExternalConnectivity invokes the driver method which does the necessary 55 // programming to allow the external connectivity dictated by the passed options 56 ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error 57 58 // RevokeExternalConnectivity asks the driver to remove any external connectivity 59 // programming that was done so far 60 RevokeExternalConnectivity(nid, eid string) error 61 62 // EventNotify notifies the driver when a CRUD operation has 63 // happened on a table of its interest as soon as this node 64 // receives such an event in the gossip layer. This method is 65 // only invoked for the global scope driver. 66 EventNotify(event EventType, nid string, tableName string, key string, value []byte) 67 68 // DecodeTableEntry passes the driver a key, value pair from table it registered 69 // with libnetwork. Driver should return {object ID, map[string]string} tuple. 70 // If DecodeTableEntry is called for a table associated with NetworkObject or 71 // EndpointObject the return object ID should be the network id or endpoint id 72 // associated with that entry. map should have information about the object that 73 // can be presented to the user. 74 // For example: overlay driver returns the VTEP IP of the host that has the endpoint 75 // which is shown in 'network inspect --verbose' 76 DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) 77 78 // Type returns the type of this driver, the network type this driver manages 79 Type() string 80 81 // IsBuiltIn returns true if it is a built-in driver 82 IsBuiltIn() bool 83 } 84 85 // NetworkInfo provides a go interface for drivers to provide network 86 // specific information to libnetwork. 87 type NetworkInfo interface { 88 // TableEventRegister registers driver interest in a given 89 // table name. 90 TableEventRegister(tableName string, objType ObjectType) error 91 92 // UpdateIPamConfig updates the networks IPAM configuration 93 // based on information from the driver. In windows, the OS (HNS) chooses 94 // the IP address space if the user does not specify an address space. 95 UpdateIpamConfig(ipV4Data []IPAMData) 96 } 97 98 // InterfaceInfo provides a go interface for drivers to retrieve 99 // network information to interface resources. 100 type InterfaceInfo interface { 101 // SetMacAddress allows the driver to set the mac address to the endpoint interface 102 // during the call to CreateEndpoint, if the mac address is not already set. 103 SetMacAddress(mac net.HardwareAddr) error 104 105 // SetIPAddress allows the driver to set the ip address to the endpoint interface 106 // during the call to CreateEndpoint, if the address is not already set. 107 // The API is to be used to assign both the IPv4 and IPv6 address types. 108 SetIPAddress(ip *net.IPNet) error 109 110 // MacAddress returns the MAC address. 111 MacAddress() net.HardwareAddr 112 113 // Address returns the IPv4 address. 114 Address() *net.IPNet 115 116 // AddressIPv6 returns the IPv6 address. 117 AddressIPv6() *net.IPNet 118 } 119 120 // InterfaceNameInfo provides a go interface for the drivers to assign names 121 // to interfaces. 122 type InterfaceNameInfo interface { 123 // SetNames method assigns the srcName and dstPrefix for the interface. 124 SetNames(srcName, dstPrefix string) error 125 } 126 127 // JoinInfo represents a set of resources that the driver has the ability to provide during 128 // join time. 129 type JoinInfo interface { 130 // InterfaceName returns an InterfaceNameInfo go interface to facilitate 131 // setting the names for the interface. 132 InterfaceName() InterfaceNameInfo 133 134 // SetGateway sets the default IPv4 gateway when a container joins the endpoint. 135 SetGateway(net.IP) error 136 137 // SetGatewayIPv6 sets the default IPv6 gateway when a container joins the endpoint. 138 SetGatewayIPv6(net.IP) error 139 140 // AddStaticRoute adds a route to the sandbox. 141 // It may be used in addition to or instead of a default gateway (as above). 142 AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error 143 144 // DisableGatewayService tells libnetwork not to provide Default GW for the container 145 DisableGatewayService() 146 147 // AddTableEntry adds a table entry to the gossip layer 148 // passing the table name, key and an opaque value. 149 AddTableEntry(tableName string, key string, value []byte) error 150 } 151 152 // Registerer provides a way for network drivers to be dynamically registered. 153 type Registerer interface { 154 RegisterDriver(name string, driver Driver, capability Capability) error 155 } 156 157 // Capability represents the high level capabilities of the drivers which libnetwork can make use of 158 type Capability struct { 159 DataScope string 160 ConnectivityScope string 161 } 162 163 // IPAMData represents the per-network ip related 164 // operational information libnetwork will send 165 // to the network driver during CreateNetwork() 166 type IPAMData struct { 167 AddressSpace string 168 Pool *net.IPNet 169 Gateway *net.IPNet 170 AuxAddresses map[string]*net.IPNet 171 } 172 173 // EventType defines a type for the CRUD event 174 type EventType uint8 175 176 const ( 177 // Create event is generated when a table entry is created, 178 Create EventType = 1 + iota 179 // Update event is generated when a table entry is updated. 180 Update 181 // Delete event is generated when a table entry is deleted. 182 Delete 183 ) 184 185 // ObjectType represents the type of object driver wants to store in libnetwork's networkDB 186 type ObjectType int 187 188 const ( 189 // EndpointObject should be set for libnetwork endpoint object related data 190 EndpointObject ObjectType = 1 + iota 191 // NetworkObject should be set for libnetwork network object related data 192 NetworkObject 193 // OpaqueObject is for driver specific data with no corresponding libnetwork object 194 OpaqueObject 195 ) 196 197 // IsValidType validates the passed in type against the valid object types 198 func IsValidType(objType ObjectType) bool { 199 switch objType { 200 case EndpointObject: 201 fallthrough 202 case NetworkObject: 203 fallthrough 204 case OpaqueObject: 205 return true 206 } 207 return false 208 }