Skip to content

Commit

Permalink
Add mgmt VRF support. (#290)
Browse files Browse the repository at this point in the history
* Add mgmt VRF support

* Update client_test.go
  • Loading branch information
liuh-80 authored Oct 12, 2024
1 parent 646b1f5 commit 2b7f8a1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
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 @@ -85,6 +85,7 @@ type Config struct {
ZmqPort string
IdleConnDuration int
ConfigTableName string
Vrf string
}

var AuthLock sync.Mutex
Expand Down Expand Up @@ -409,7 +410,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 @@ -507,7 +508,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 @@ -584,7 +585,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
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 2b7f8a1

Please sign in to comment.