driverapi.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package driverapi
  2. import (
  3. "net"
  4. "github.com/docker/docker/pkg/plugingetter"
  5. "github.com/docker/libnetwork/discoverapi"
  6. )
  7. // NetworkPluginEndpointType represents the Endpoint Type used by Plugin system
  8. const NetworkPluginEndpointType = "NetworkDriver"
  9. // Driver is an interface that every plugin driver needs to implement.
  10. type Driver interface {
  11. discoverapi.Discover
  12. // NetworkAllocate invokes the driver method to allocate network
  13. // specific resources passing network id and network specific config.
  14. // It returns a key,value pair of network specific driver allocations
  15. // to the caller.
  16. NetworkAllocate(nid string, options map[string]string, ipV4Data, ipV6Data []IPAMData) (map[string]string, error)
  17. // NetworkFree invokes the driver method to free network specific resources
  18. // associated with a given network id.
  19. NetworkFree(nid string) error
  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. // DeleteNetwork invokes the driver method to delete network passing
  30. // the network id.
  31. DeleteNetwork(nid string) error
  32. // CreateEndpoint invokes the driver method to create an endpoint
  33. // passing the network id, endpoint id endpoint information and driver
  34. // specific config. The endpoint information can be either consumed by
  35. // the driver or populated by the driver. The config mechanism will
  36. // eventually be replaced with labels which are yet to be introduced.
  37. CreateEndpoint(nid, eid string, ifInfo InterfaceInfo, options map[string]interface{}) error
  38. // DeleteEndpoint invokes the driver method to delete an endpoint
  39. // passing the network id and endpoint id.
  40. DeleteEndpoint(nid, eid string) error
  41. // EndpointOperInfo retrieves from the driver the operational data related to the specified endpoint
  42. EndpointOperInfo(nid, eid string) (map[string]interface{}, error)
  43. // Join method is invoked when a Sandbox is attached to an endpoint.
  44. Join(nid, eid string, sboxKey string, jinfo JoinInfo, options map[string]interface{}) error
  45. // Leave method is invoked when a Sandbox detaches from an endpoint.
  46. Leave(nid, eid string) error
  47. // ProgramExternalConnectivity invokes the driver method which does the necessary
  48. // programming to allow the external connectivity dictated by the passed options
  49. ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error
  50. // RevokeExternalConnectivity asks the driver to remove any external connectivity
  51. // programming that was done so far
  52. RevokeExternalConnectivity(nid, eid string) error
  53. // EventNotify notifies the driver when a CRUD operation has
  54. // happened on a table of its interest as soon as this node
  55. // receives such an event in the gossip layer. This method is
  56. // only invoked for the global scope driver.
  57. EventNotify(event EventType, nid string, tableName string, key string, value []byte)
  58. // Type returns the type of this driver, the network type this driver manages
  59. Type() string
  60. // IsBuiltIn returns true if it is a built-in driver
  61. IsBuiltIn() bool
  62. }
  63. // NetworkInfo provides a go interface for drivers to provide network
  64. // specific information to libnetwork.
  65. type NetworkInfo interface {
  66. // TableEventRegister registers driver interest in a given
  67. // table name.
  68. TableEventRegister(tableName string) error
  69. }
  70. // InterfaceInfo provides a go interface for drivers to retrive
  71. // network information to interface resources.
  72. type InterfaceInfo interface {
  73. // SetMacAddress allows the driver to set the mac address to the endpoint interface
  74. // during the call to CreateEndpoint, if the mac address is not already set.
  75. SetMacAddress(mac net.HardwareAddr) error
  76. // SetIPAddress allows the driver to set the ip address to the endpoint interface
  77. // during the call to CreateEndpoint, if the address is not already set.
  78. // The API is to be used to assign both the IPv4 and IPv6 address types.
  79. SetIPAddress(ip *net.IPNet) error
  80. // MacAddress returns the MAC address.
  81. MacAddress() net.HardwareAddr
  82. // Address returns the IPv4 address.
  83. Address() *net.IPNet
  84. // AddressIPv6 returns the IPv6 address.
  85. AddressIPv6() *net.IPNet
  86. }
  87. // InterfaceNameInfo provides a go interface for the drivers to assign names
  88. // to interfaces.
  89. type InterfaceNameInfo interface {
  90. // SetNames method assigns the srcName and dstPrefix for the interface.
  91. SetNames(srcName, dstPrefix string) error
  92. }
  93. // JoinInfo represents a set of resources that the driver has the ability to provide during
  94. // join time.
  95. type JoinInfo interface {
  96. // InterfaceName returns an InterfaceNameInfo go interface to facilitate
  97. // setting the names for the interface.
  98. InterfaceName() InterfaceNameInfo
  99. // SetGateway sets the default IPv4 gateway when a container joins the endpoint.
  100. SetGateway(net.IP) error
  101. // SetGatewayIPv6 sets the default IPv6 gateway when a container joins the endpoint.
  102. SetGatewayIPv6(net.IP) error
  103. // AddStaticRoute adds a route to the sandbox.
  104. // It may be used in addition to or instead of a default gateway (as above).
  105. AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error
  106. // DisableGatewayService tells libnetwork not to provide Default GW for the container
  107. DisableGatewayService()
  108. // AddTableEntry adds a table entry to the gossip layer
  109. // passing the table name, key and an opaque value.
  110. AddTableEntry(tableName string, key string, value []byte) error
  111. }
  112. // DriverCallback provides a Callback interface for Drivers into LibNetwork
  113. type DriverCallback interface {
  114. // GetPluginGetter returns the pluginv2 getter.
  115. GetPluginGetter() plugingetter.PluginGetter
  116. // RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
  117. RegisterDriver(name string, driver Driver, capability Capability) error
  118. }
  119. // Capability represents the high level capabilities of the drivers which libnetwork can make use of
  120. type Capability struct {
  121. DataScope string
  122. }
  123. // IPAMData represents the per-network ip related
  124. // operational information libnetwork will send
  125. // to the network driver during CreateNetwork()
  126. type IPAMData struct {
  127. AddressSpace string
  128. Pool *net.IPNet
  129. Gateway *net.IPNet
  130. AuxAddresses map[string]*net.IPNet
  131. }
  132. // EventType defines a type for the CRUD event
  133. type EventType uint8
  134. const (
  135. // Create event is generated when a table entry is created,
  136. Create EventType = 1 + iota
  137. // Update event is generated when a table entry is updated.
  138. Update
  139. // Delete event is generated when a table entry is deleted.
  140. Delete
  141. )