Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into gnoi-reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
ndas7 authored Oct 16, 2024
2 parents b972ac4 + 743c7af commit 78572f4
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ endif
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(GO) test -race -coverprofile=coverage-data.txt -covermode=atomic -mod=vendor -v github.com/sonic-net/sonic-gnmi/sonic_data_client
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(GO) test -race -coverprofile=coverage-dbus.txt -covermode=atomic -mod=vendor -v github.com/sonic-net/sonic-gnmi/sonic_service_client
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(TESTENV) $(GO) test -race -coverprofile=coverage-translutils.txt -covermode=atomic -mod=vendor -v github.com/sonic-net/sonic-gnmi/transl_utils
$(GO) install github.com/axw/gocov/gocov@latest
$(GO) install github.com/axw/gocov/gocov@v1.1.0
$(GO) install github.com/AlekSi/gocov-xml@latest
$(GO) mod vendor
gocov convert coverage-*.txt | gocov-xml -source $(shell pwd) > coverage.xml
Expand Down
2 changes: 1 addition & 1 deletion gnmi_server/client_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {
if origin == "openconfig" {
dc, err = sdc.NewTranslClient(prefix, paths, ctx, extensions, sdc.TranslWildcardOption{})
} else if IsNativeOrigin(origin) {
dc, err = sdc.NewMixedDbClient(paths, prefix, origin, gnmipb.Encoding_JSON_IETF, "")
dc, err = sdc.NewMixedDbClient(paths, prefix, origin, gnmipb.Encoding_JSON_IETF, "", "")
} else if len(origin) != 0 {
return grpc.Errorf(codes.Unimplemented, "Unsupported origin: %s", origin)
} else if target == "" {
Expand Down
7 changes: 4 additions & 3 deletions gnmi_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type Config struct {
ZmqPort string
IdleConnDuration int
ConfigTableName string
Vrf string
}

var AuthLock sync.Mutex
Expand Down Expand Up @@ -401,7 +402,7 @@ func (s *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetRe
}
}
if check := IsNativeOrigin(origin); check {
dc, err = sdc.NewMixedDbClient(paths, prefix, origin, encoding, s.config.ZmqPort)
dc, err = sdc.NewMixedDbClient(paths, prefix, origin, encoding, s.config.ZmqPort, s.config.Vrf)
} else {
dc, err = sdc.NewTranslClient(prefix, paths, ctx, extensions)
}
Expand Down Expand Up @@ -499,7 +500,7 @@ func (s *Server) Set(ctx context.Context, req *gnmipb.SetRequest) (*gnmipb.SetRe
common_utils.IncCounter(common_utils.GNMI_SET_FAIL)
return nil, grpc.Errorf(codes.Unimplemented, "GNMI native write is disabled")
}
dc, err = sdc.NewMixedDbClient(paths, prefix, origin, encoding, s.config.ZmqPort)
dc, err = sdc.NewMixedDbClient(paths, prefix, origin, encoding, s.config.ZmqPort, s.config.Vrf)
} else {
if s.config.EnableTranslibWrite == false {
common_utils.IncCounter(common_utils.GNMI_SET_FAIL)
Expand Down Expand Up @@ -576,7 +577,7 @@ func (s *Server) Capabilities(ctx context.Context, req *gnmipb.CapabilityRequest
var supportedModels []gnmipb.ModelData
dc, _ := sdc.NewTranslClient(nil, nil, ctx, extensions)
supportedModels = append(supportedModels, dc.Capabilities()...)
dc, _ = sdc.NewMixedDbClient(nil, nil, "", gnmipb.Encoding_JSON_IETF, s.config.ZmqPort)
dc, _ = sdc.NewMixedDbClient(nil, nil, "", gnmipb.Encoding_JSON_IETF, s.config.ZmqPort, s.config.Vrf)
supportedModels = append(supportedModels, dc.Capabilities()...)

suppModels := make([]*gnmipb.ModelData, len(supportedModels))
Expand Down
6 changes: 3 additions & 3 deletions sonic_data_client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,17 +793,17 @@ func TestGetZmqClient(t *testing.T) {
dpusTable.Hset("dpu0", "midplane_interface", "dpu0")
dhcpPortTable.Hset("bridge-midplane|dpu0", "ips@", "127.0.0.2,127.0.0.1")

client, err := getZmqClient("dpu0", "")
client, err := getZmqClient("dpu0", "", "")
if client != nil || err != nil {
t.Errorf("empty ZMQ port should not get ZMQ client")
}

client, err = getZmqClient("dpu0", "1234")
client, err = getZmqClient("dpu0", "1234", "")
if client == nil {
t.Errorf("get ZMQ client failed")
}

client, err = getZmqClient("", "1234")
client, err = getZmqClient("", "1234", "")
if client == nil {
t.Errorf("get ZMQ client failed")
}
Expand Down
14 changes: 7 additions & 7 deletions sonic_data_client/mixed_db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ func getZmqAddress(container string, zmqPort string) (string, error) {

var zmqClientMap = map[string]swsscommon.ZmqClient{}

func getZmqClientByAddress(zmqAddress string) (swsscommon.ZmqClient, error) {
func getZmqClientByAddress(zmqAddress string, vrf string) (swsscommon.ZmqClient, error) {
client, ok := zmqClientMap[zmqAddress]
if !ok {
client = swsscommon.NewZmqClient(zmqAddress)
client = swsscommon.NewZmqClient(zmqAddress, vrf)
zmqClientMap[zmqAddress] = client
}

Expand All @@ -181,23 +181,23 @@ func removeZmqClient(zmqClient swsscommon.ZmqClient) (error) {
return fmt.Errorf("Can't find ZMQ client in zmqClientMap: %v", zmqClient)
}

func getZmqClient(dpuId string, zmqPort string) (swsscommon.ZmqClient, error) {
func getZmqClient(dpuId string, zmqPort string, vrf string) (swsscommon.ZmqClient, error) {
if zmqPort == "" {
// ZMQ feature disabled when zmqPort flag not set
return nil, nil
}

if dpuId == sdcfg.SONIC_DEFAULT_CONTAINER {
// When DPU ID is default, create ZMQ with local address
return getZmqClientByAddress("tcp://" + LOCAL_ADDRESS + ":" + zmqPort)
return getZmqClientByAddress("tcp://" + LOCAL_ADDRESS + ":" + zmqPort, vrf)
}

zmqAddress, err := getZmqAddress(dpuId, zmqPort)
if err != nil {
return nil, fmt.Errorf("Get ZMQ address failed: %v", err)
}

return getZmqClientByAddress(zmqAddress)
return getZmqClientByAddress(zmqAddress, vrf)
}

// This function get target present in GNMI Request and
Expand Down Expand Up @@ -493,7 +493,7 @@ func init() {
initRedisDbMap()
}

func NewMixedDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path, origin string, encoding gnmipb.Encoding, zmqPort string) (Client, error) {
func NewMixedDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path, origin string, encoding gnmipb.Encoding, zmqPort string, vrf string) (Client, error) {
var err error

// Initialize RedisDbMap for test
Expand Down Expand Up @@ -556,7 +556,7 @@ func NewMixedDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path, origin string,
client.workPath = common_utils.GNMI_WORK_PATH

// continer is DPU ID
client.zmqClient, err = getZmqClient(container, zmqPort)
client.zmqClient, err = getZmqClient(container, zmqPort, vrf)
if err != nil {
return nil, fmt.Errorf("Get ZMQ client failed: %v", err)
}
Expand Down
20 changes: 10 additions & 10 deletions sonic_service_client/dbus_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (c *DbusClient) ConfigReload(config string) error {
busName := c.busNamePrefix + modName
busPath := c.busPathPrefix + modName
intName := c.intNamePrefix + modName + ".reload"
_, err := DbusApi(busName, busPath, intName, 10, config)
_, err := DbusApi(busName, busPath, intName, 60, config)
return err
}

Expand All @@ -114,7 +114,7 @@ func (c *DbusClient) ConfigSave(fileName string) error {
busName := c.busNamePrefix + modName
busPath := c.busPathPrefix + modName
intName := c.intNamePrefix + modName + ".save"
_, err := DbusApi(busName, busPath, intName, 10, fileName)
_, err := DbusApi(busName, busPath, intName, 60, fileName)
return err
}

Expand All @@ -124,7 +124,7 @@ func (c *DbusClient) ApplyPatchYang(patch string) error {
busName := c.busNamePrefix + modName
busPath := c.busPathPrefix + modName
intName := c.intNamePrefix + modName + ".apply_patch_yang"
_, err := DbusApi(busName, busPath, intName, 180, patch)
_, err := DbusApi(busName, busPath, intName, 240, patch)
return err
}

Expand All @@ -134,7 +134,7 @@ func (c *DbusClient) ApplyPatchDb(patch string) error {
busName := c.busNamePrefix + modName
busPath := c.busPathPrefix + modName
intName := c.intNamePrefix + modName + ".apply_patch_db"
_, err := DbusApi(busName, busPath, intName, 180, patch)
_, err := DbusApi(busName, busPath, intName, 240, patch)
return err
}

Expand All @@ -144,7 +144,7 @@ func (c *DbusClient) CreateCheckPoint(fileName string) error {
busName := c.busNamePrefix + modName
busPath := c.busPathPrefix + modName
intName := c.intNamePrefix + modName + ".create_checkpoint"
_, err := DbusApi(busName, busPath, intName, 10, fileName)
_, err := DbusApi(busName, busPath, intName, 60, fileName)
return err
}

Expand All @@ -154,7 +154,7 @@ func (c *DbusClient) DeleteCheckPoint(fileName string) error {
busName := c.busNamePrefix + modName
busPath := c.busPathPrefix + modName
intName := c.intNamePrefix + modName + ".delete_checkpoint"
_, err := DbusApi(busName, busPath, intName, 10, fileName)
_, err := DbusApi(busName, busPath, intName, 60, fileName)
return err
}

Expand All @@ -164,7 +164,7 @@ func (c *DbusClient) StopService(service string) error {
busName := c.busNamePrefix + modName
busPath := c.busPathPrefix + modName
intName := c.intNamePrefix + modName + ".stop_service"
_, err := DbusApi(busName, busPath, intName, 90, service)
_, err := DbusApi(busName, busPath, intName, 240, service)
return err
}

Expand All @@ -174,7 +174,7 @@ func (c *DbusClient) RestartService(service string) error {
busName := c.busNamePrefix + modName
busPath := c.busPathPrefix + modName
intName := c.intNamePrefix + modName + ".restart_service"
_, err := DbusApi(busName, busPath, intName, 90, service)
_, err := DbusApi(busName, busPath, intName, 240, service)
return err
}

Expand All @@ -184,10 +184,10 @@ func (c *DbusClient) GetFileStat(path string) (map[string]string, error) {
busName := c.busNamePrefix + modName
busPath := c.busPathPrefix + modName
intName := c.intNamePrefix + modName + ".get_file_stat"
result, err := DbusApi(busName, busPath, intName, 10, path)
result, err := DbusApi(busName, busPath, intName, 60, path)
if err != nil {
return nil, err
}
data, _ := result.(map[string]string)
return data, nil
}
}
3 changes: 3 additions & 0 deletions telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type TelemetryConfig struct {
WithMasterArbitration *bool
WithSaveOnSet *bool
IdleConnDuration *int
Vrf *string
}

func main() {
Expand Down Expand Up @@ -165,6 +166,7 @@ func setupFlags(fs *flag.FlagSet) (*TelemetryConfig, *gnmi.Config, error) {
WithMasterArbitration: fs.Bool("with-master-arbitration", false, "Enables master arbitration policy."),
WithSaveOnSet: fs.Bool("with-save-on-set", false, "Enables save-on-set."),
IdleConnDuration: fs.Int("idle_conn_duration", 5, "Seconds before server closes idle connections"),
Vrf: fs.String("vrf", "", "VRF name, when zmq_address belong on a VRF, need VRF name to bind ZMQ."),
}

fs.Var(&telemetryCfg.UserAuth, "client_auth", "Client auth mode(s) - none,cert,password")
Expand Down Expand Up @@ -227,6 +229,7 @@ func setupFlags(fs *flag.FlagSet) (*TelemetryConfig, *gnmi.Config, error) {
cfg.Threshold = int(*telemetryCfg.Threshold)
cfg.IdleConnDuration = int(*telemetryCfg.IdleConnDuration)
cfg.ConfigTableName = *telemetryCfg.ConfigTableName
cfg.Vrf = *telemetryCfg.Vrf

// TODO: After other dependent projects are migrated to ZmqPort, remove ZmqAddress
zmqAddress := *telemetryCfg.ZmqAddress
Expand Down

0 comments on commit 78572f4

Please sign in to comment.