driverapi.go 6.6 KB

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