...

Source file src/github.com/Microsoft/hcsshim/internal/tools/networkagent/defs.go

Documentation: github.com/Microsoft/hcsshim/internal/tools/networkagent

     1  //go:build windows
     2  
     3  package main
     4  
     5  import (
     6  	"encoding/json"
     7  	"os"
     8  
     9  	ncproxygrpc "github.com/Microsoft/hcsshim/pkg/ncproxy/ncproxygrpc/v1"
    10  	nodenetsvcV0 "github.com/Microsoft/hcsshim/pkg/ncproxy/nodenetsvc/v0"
    11  	"github.com/pkg/errors"
    12  )
    13  
    14  type service struct {
    15  	conf                 *config
    16  	client               ncproxygrpc.NetworkConfigProxyClient
    17  	containerToNamespace map[string]string
    18  	endpointToNicID      map[string]string
    19  	containerToNetwork   map[string][]string
    20  }
    21  
    22  type v0ServiceWrapper struct {
    23  	s *service
    24  	nodenetsvcV0.UnimplementedNodeNetworkServiceServer
    25  }
    26  
    27  type hnsSettings struct {
    28  	SwitchName  string                                `json:"switch_name,omitempty"`
    29  	IOVSettings *ncproxygrpc.IovEndpointPolicySetting `json:"iov_settings,omitempty"`
    30  }
    31  
    32  type ncproxynetworkingSettings struct {
    33  	DeviceID             string `json:"device_id,omitempty"`
    34  	VirtualFunctionIndex uint32 `json:"virtual_function_index,omitempty"`
    35  }
    36  
    37  type networkingSettings struct {
    38  	HNSSettings               *hnsSettings               `json:"hns_settings,omitempty"`
    39  	NCProxyNetworkingSettings *ncproxynetworkingSettings `json:"ncproxy_networking_settings,omitempty"`
    40  }
    41  
    42  type config struct {
    43  	TTRPCAddr      string `json:"ttrpc,omitempty"`
    44  	GRPCAddr       string `json:"grpc,omitempty"`
    45  	NodeNetSvcAddr string `json:"node_net_svc_addr,omitempty"`
    46  	// 0 represents no timeout and networkagent will continuously try and connect in the
    47  	// background.
    48  	Timeout            uint32              `json:"timeout,omitempty"`
    49  	NetworkingSettings *networkingSettings `json:"networking_settings,omitempty"`
    50  }
    51  
    52  // Reads config from path and returns config struct if path is valid and marshaling
    53  // succeeds
    54  func readConfig(path string) (*config, error) {
    55  	data, err := os.ReadFile(path)
    56  	if err != nil {
    57  		return nil, errors.Wrap(err, "failed to read config file")
    58  	}
    59  	conf := &config{}
    60  	if err := json.Unmarshal(data, conf); err != nil {
    61  		return nil, errors.New("failed to unmarshal config data")
    62  	}
    63  	return conf, nil
    64  }
    65  

View as plain text