Skip to content

Commit

Permalink
Merge pull request #1067 from katiewasnothere/test_network_agent
Browse files Browse the repository at this point in the history
Add test network agent for ncproxy dev work
  • Loading branch information
katiewasnothere committed Oct 8, 2021
2 parents 2a4f814 + 2d0978c commit 1b1197b
Show file tree
Hide file tree
Showing 8 changed files with 1,555 additions and 112 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ jobs:
- run: go build ./cmd/ncproxy
- run: go build ./cmd/dmverity-vhd
- run: go build ./internal/tools/grantvmgroupaccess
- run: go build ./internal/tools/networkagent
- run: go build ./internal/tools/securitypolicy
- run: go build ./internal/tools/uvmboot
- run: go build ./internal/tools/zapdir
Expand All @@ -125,6 +126,7 @@ jobs:
device-util.exe
wclayer.exe
grantvmgroupaccess.exe
networkagent.exe
uvmboot.exe
zapdir.exe
ncproxy.exe
Expand Down
10 changes: 10 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ issues:
linters:
- stylecheck
Text: "ST1003:"

- path: cmd\\ncproxy\\nodenetsvc\\
linters:
- stylecheck
Text: "ST1003:"

- path: cmd\\ncproxy_mock\\
linters:
- stylecheck
Text: "ST1003:"

- path: internal\\hcs\\schema2\\
linters:
Expand Down
35 changes: 35 additions & 0 deletions cmd/ncproxy/ncproxy_mock/nodenetsvc_mock.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,160 changes: 1,065 additions & 95 deletions cmd/ncproxy/nodenetsvc/nodenetsvc.pb.go

Large diffs are not rendered by default.

55 changes: 38 additions & 17 deletions cmd/ncproxy/nodenetsvc/nodenetsvc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,57 @@ service NodeNetworkService {
rpc ConfigureNetworking(ConfigureNetworkingRequest) returns (ConfigureNetworkingResponse);
rpc ConfigureContainerNetworking(ConfigureContainerNetworkingRequest) returns (ConfigureContainerNetworkingResponse);
rpc PingNodeNetworkService(PingNodeNetworkServiceRequest) returns (PingNodeNetworkServiceResponse);
rpc GetHostLocalIpAddress(GetHostLocalIpAddressRequest) returns (GetHostLocalIpAddressResponse);
}

enum RequestType {
Setup = 0;
Teardown = 1;
}


message ConfigureNetworkingRequest {
string container_id = 1;
RequestType request_type = 2; // Setup for AddNIC and Teardown for DeleteNIC
RequestType request_type = 2;
}

message ConfigureNetworkingResponse{}
message ConfigureNetworkingResponse {}

message PingNodeNetworkServiceRequest {
string pingRequestMessage = 1;
string ping_request_message = 1;
}

message PingNodeNetworkServiceResponse {
string pingResponseMessage = 1;
string ping_response_message = 1;
}

enum RequestType {
Setup = 0;
Teardown = 1;
}

message ConfigureContainerNetworkingRequest{
message ConfigureContainerNetworkingRequest {
RequestType request_type = 1;
string container_id = 2;
string network_namespace = 3;
string network_namespace_id = 3;
}

message ConfigureContainerNetworkingResponse {
repeated ContainerNetworkInterface interfaces = 1;
}

message ConfigureContainerNetworkingResponse {
bool success = 1;
string response_json = 2;
string error_json= 3;
}
message ContainerIPAddress {
string version = 1;
string ip = 3;
string prefix_length = 4;
string default_gateway = 5;
}

message ContainerNetworkInterface {
string name = 1;
string mac_address = 2;
string network_namespace_id = 3;
repeated ContainerIPAddress ipaddresses = 4;
}

message GetHostLocalIpAddressRequest {
string container_id = 1;
}

message GetHostLocalIpAddressResponse {
string ip_addr = 1;
}
50 changes: 50 additions & 0 deletions internal/tools/networkagent/defs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"encoding/json"
"io/ioutil"

"github.com/Microsoft/hcsshim/cmd/ncproxy/ncproxygrpc"
"github.com/pkg/errors"
)

type service struct {
conf *config
client ncproxygrpc.NetworkConfigProxyClient
containerToNamespace map[string]string
endpointToNicID map[string]string
containerToNetwork map[string]string
}

type hnsSettings struct {
SwitchName string `json:"switch_name,omitempty"`
IOVSettings *ncproxygrpc.IovEndpointPolicySetting `json:"iov_settings,omitempty"`
}

type networkingSettings struct {
HNSSettings *hnsSettings `json:"hns_settings,omitempty"`
}

type config struct {
TTRPCAddr string `json:"ttrpc,omitempty"`
GRPCAddr string `json:"grpc,omitempty"`
NodeNetSvcAddr string `json:"node_net_svc_addr,omitempty"`
// 0 represents no timeout and networkagent will continuously try and connect in the
// background.
Timeout uint32 `json:"timeout,omitempty"`
NetworkingSettings *networkingSettings `json:"networking_settings,omitempty"`
}

// Reads config from path and returns config struct if path is valid and marshaling
// succeeds
func readConfig(path string) (*config, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, errors.Wrap(err, "failed to read config file")
}
conf := &config{}
if err := json.Unmarshal(data, conf); err != nil {
return nil, errors.New("failed to unmarshal config data")
}
return conf, nil
}

0 comments on commit 1b1197b

Please sign in to comment.