diff --git a/adapters/secondary/local_networking/hns/repository.go b/adapters/secondary/local_networking/hns/contrail_network_repository.go similarity index 100% rename from adapters/secondary/local_networking/hns/repository.go rename to adapters/secondary/local_networking/hns/contrail_network_repository.go diff --git a/adapters/secondary/local_networking/hns/endpoint_repository.go b/adapters/secondary/local_networking/hns/endpoint_repository.go new file mode 100644 index 0000000..c1cd015 --- /dev/null +++ b/adapters/secondary/local_networking/hns/endpoint_repository.go @@ -0,0 +1,34 @@ +// +// Copyright (c) 2018 Juniper Networks, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package hns + +import ( + "github.com/Microsoft/hcsshim" +) + +type HNSEndpointRepository struct{} + +func (repo *HNSEndpointRepository) CreateEndpoint(configuration *hcsshim.HNSEndpoint) (string, error) { + return CreateHNSEndpoint(configuration) +} + +func (repo *HNSEndpointRepository) GetEndpointByName(name string) (*hcsshim.HNSEndpoint, error) { + return GetHNSEndpointByName(name) +} + +func (repo *HNSEndpointRepository) DeleteEndpoint(endpointID string) error { + return DeleteHNSEndpoint(endpointID) +} diff --git a/adapters/secondary/local_networking/simulator/repository.go b/adapters/secondary/local_networking/simulator/contrail_network_repository.go similarity index 100% rename from adapters/secondary/local_networking/simulator/repository.go rename to adapters/secondary/local_networking/simulator/contrail_network_repository.go diff --git a/adapters/secondary/local_networking/simulator/endpoint_repository.go b/adapters/secondary/local_networking/simulator/endpoint_repository.go new file mode 100644 index 0000000..bc8928a --- /dev/null +++ b/adapters/secondary/local_networking/simulator/endpoint_repository.go @@ -0,0 +1,36 @@ +// +// Copyright (c) 2018 Juniper Networks, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package simulator + +import ( + "errors" + + "github.com/Microsoft/hcsshim" +) + +type InMemEndpointRepository struct{} + +func (repo *InMemEndpointRepository) CreateEndpoint(configuration *hcsshim.HNSEndpoint) (string, error) { + return "", errors.New("Not implemented yet") +} + +func (repo *InMemEndpointRepository) GetEndpointByName(name string) (*hcsshim.HNSEndpoint, error) { + return nil, errors.New("Not implemented yet") +} + +func (repo *InMemEndpointRepository) DeleteEndpoint(endpointID string) error { + return errors.New("Not implemented yet") +} diff --git a/core/driver/driver.go b/core/driver/driver.go index a04046f..83f108e 100644 --- a/core/driver/driver.go +++ b/core/driver/driver.go @@ -45,16 +45,17 @@ import ( const hnsEndpointWaitingTime = 5 type ContrailDriver struct { - vrouter VRouter - controller Controller - agent Agent - localContrailNetworksRepo LocalContrailNetworkRepository - networkAdapter common.AdapterName - listener net.Listener - PipeAddr string - stopReasonChan chan error - stoppedServingChan chan interface{} - IsServing bool + vrouter VRouter + controller Controller + agent Agent + localContrailNetworksRepo LocalContrailNetworkRepository + localContrailEndpointsRepo LocalContrailEndpointRepository + networkAdapter common.AdapterName + listener net.Listener + PipeAddr string + stopReasonChan chan error + stoppedServingChan chan interface{} + IsServing bool } type NetworkMeta struct { @@ -64,18 +65,19 @@ type NetworkMeta struct { } func NewDriver(adapter string, vr VRouter, c Controller, agent Agent, - localContrailNetworksRepo LocalContrailNetworkRepository) *ContrailDriver { + networksRepo LocalContrailNetworkRepository, endpointsRepo LocalContrailEndpointRepository) *ContrailDriver { d := &ContrailDriver{ vrouter: vr, controller: c, agent: agent, - localContrailNetworksRepo: localContrailNetworksRepo, - networkAdapter: common.AdapterName(adapter), - PipeAddr: "//./pipe/" + common.DriverName, - stopReasonChan: make(chan error, 1), - stoppedServingChan: make(chan interface{}, 1), - IsServing: false, + localContrailNetworksRepo: networksRepo, + localContrailEndpointsRepo: endpointsRepo, + networkAdapter: common.AdapterName(adapter), + PipeAddr: "//./pipe/" + common.DriverName, + stopReasonChan: make(chan error, 1), + stoppedServingChan: make(chan interface{}, 1), + IsServing: false, } return d } @@ -409,7 +411,7 @@ func (d *ContrailDriver) CreateEndpoint(req *network.CreateEndpointRequest) ( GatewayAddress: contrailGateway, } - hnsEndpointID, err := hns.CreateHNSEndpoint(hnsEndpointConfig) + hnsEndpointID, err := d.localContrailEndpointsRepo.CreateEndpoint(hnsEndpointConfig) if err != nil { return nil, err } @@ -489,7 +491,7 @@ func (d *ContrailDriver) DeleteEndpoint(req *network.DeleteEndpointRequest) erro } hnsEpName := req.EndpointID - epToDelete, err := hns.GetHNSEndpointByName(hnsEpName) + epToDelete, err := d.localContrailEndpointsRepo.GetEndpointByName(hnsEpName) if err != nil { return err } @@ -498,7 +500,7 @@ func (d *ContrailDriver) DeleteEndpoint(req *network.DeleteEndpointRequest) erro return nil } - return hns.DeleteHNSEndpoint(epToDelete.Id) + return d.localContrailEndpointsRepo.DeleteEndpoint(epToDelete.Id) } func (d *ContrailDriver) EndpointInfo(req *network.InfoRequest) (*network.InfoResponse, error) { @@ -506,7 +508,7 @@ func (d *ContrailDriver) EndpointInfo(req *network.InfoRequest) (*network.InfoRe log.Debugln(req) hnsEpName := req.EndpointID - hnsEp, err := hns.GetHNSEndpointByName(hnsEpName) + hnsEp, err := d.localContrailEndpointsRepo.GetEndpointByName(hnsEpName) if err != nil { return nil, err } @@ -533,7 +535,7 @@ func (d *ContrailDriver) Join(req *network.JoinRequest) (*network.JoinResponse, fmt.Printf("%v: %v\n", k, v) } - hnsEp, err := hns.GetHNSEndpointByName(req.EndpointID) + hnsEp, err := d.localContrailEndpointsRepo.GetEndpointByName(req.EndpointID) if err != nil { return nil, err } @@ -553,7 +555,7 @@ func (d *ContrailDriver) Leave(req *network.LeaveRequest) error { log.Debugln("=== Leave") log.Debugln(req) - hnsEp, err := hns.GetHNSEndpointByName(req.EndpointID) + hnsEp, err := d.localContrailEndpointsRepo.GetEndpointByName(req.EndpointID) if err != nil { return err } diff --git a/core/driver/driver_test.go b/core/driver/driver_test.go index f22e59c..8f81686 100644 --- a/core/driver/driver_test.go +++ b/core/driver/driver_test.go @@ -812,10 +812,11 @@ func newModulesUnderTest() (vr driver.VRouter, d *driver.ContrailDriver, c drive p, err = c.NewProject(common.DomainName, tenantName) Expect(err).ToNot(HaveOccurred()) - r := &netSim.InMemContrailNetworksRepository{} + netRepo := &netSim.InMemContrailNetworksRepository{} + epRepo := &netSim.InMemEndpointRepository{} serverUrl, _ := url.Parse("http://127.0.0.1:9091") a := agent.NewAgentRestAPI(http.DefaultClient, serverUrl) - d = driver.NewDriver(netAdapter, vr, c, a, r) + d = driver.NewDriver(netAdapter, vr, c, a, netRepo, epRepo) return } diff --git a/core/driver/local_networking.go b/core/driver/local_networking.go index 397b402..0d8223a 100644 --- a/core/driver/local_networking.go +++ b/core/driver/local_networking.go @@ -28,3 +28,9 @@ type LocalContrailNetworkRepository interface { DeleteNetwork(tenantName, networkName, subnetCIDR string) error ListNetworks() ([]hcsshim.HNSNetwork, error) } + +type LocalContrailEndpointRepository interface { + CreateEndpoint(configuration *hcsshim.HNSEndpoint) (string, error) + GetEndpointByName(name string) (*hcsshim.HNSEndpoint, error) + DeleteEndpoint(endpointID string) error +} diff --git a/main.go b/main.go index 4807d76..86a5d5e 100644 --- a/main.go +++ b/main.go @@ -148,8 +148,9 @@ func (ws *WinService) Execute(args []string, winChangeReqChan <-chan svc.ChangeR } agent := agent.NewAgentRestAPI(http.DefaultClient, agentUrl) - repo := &hns.HNSContrailNetworksRepository{} - d := driver.NewDriver(ws.adapter, vrouter, controller, agent, repo) + netRepo := &hns.HNSContrailNetworksRepository{} + epRepo := &hns.HNSEndpointRepository{} + d := driver.NewDriver(ws.adapter, vrouter, controller, agent, netRepo, epRepo) if err = d.StartServing(); err != nil { log.Error(err) return