Skip to content

Commit

Permalink
Add test network agent for ncproxy dev work
Browse files Browse the repository at this point in the history
Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
  • Loading branch information
katiewasnothere committed Jul 9, 2021
1 parent 657ae58 commit c4cd8fc
Show file tree
Hide file tree
Showing 2 changed files with 510 additions and 0 deletions.
57 changes: 57 additions & 0 deletions cmd/networkagent/defs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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
containerToNICVirtualFunctionID map[string]string
containerToNetwork map[string]string
}

type nicWithVFSettings struct {
ID string `json:"id,omitempty"`
VirtualFunctionIndex uint32 `json:"virtual_function_index,omitempty"`
}

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

type networkingSettings struct {
NICWithVFSettings *nicWithVFSettings `json:"nic_with_vf_settings,omitempty"`
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 ncproxy 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
}
Loading

0 comments on commit c4cd8fc

Please sign in to comment.