[SEBA-660] : Adding Igmp support in BbSim

Change-Id: I9f5c7d8ad39ac82850b04e2c997996d6c47b32d2
diff --git a/internal/bbsimctl/commands/onu.go b/internal/bbsimctl/commands/onu.go
index 620e052..515ba07 100644
--- a/internal/bbsimctl/commands/onu.go
+++ b/internal/bbsimctl/commands/onu.go
@@ -35,6 +35,11 @@
 )
 
 type OnuSnString string
+type IgmpSubAction string
+
+const IgmpJoinKey string = "join"
+const IgmpLeaveKey string = "leave"
+
 type ONUList struct{}
 
 type ONUGet struct {
@@ -67,6 +72,13 @@
 	} `positional-args:"yes" required:"yes"`
 }
 
+type ONUIgmp struct {
+	Args struct {
+		OnuSn     OnuSnString
+		SubAction IgmpSubAction
+	} `positional-args:"yes" required:"yes"`
+}
+
 type ONUOptions struct {
 	List         ONUList         `command:"list"`
 	Get          ONUGet          `command:"get"`
@@ -74,6 +86,7 @@
 	PowerOn      ONUPowerOn      `command:"poweron"`
 	RestartEapol ONUEapolRestart `command:"auth_restart"`
 	RestartDchp  ONUDhcpRestart  `command:"dhcp_restart"`
+	Igmp         ONUIgmp         `command:"igmp"`
 }
 
 func RegisterONUCommands(parser *flags.Parser) {
@@ -228,6 +241,53 @@
 	return nil
 }
 
+func (options *ONUIgmp) Execute(args []string) error {
+	client, conn := connect()
+	defer conn.Close()
+
+	ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
+	defer cancel()
+
+	req := pb.ONURequest{
+		SerialNumber: string(options.Args.OnuSn),
+	}
+
+	var subActionVal pb.SubActionTypes
+	if string(options.Args.SubAction) == IgmpJoinKey {
+		subActionVal = pb.SubActionTypes_JOIN
+	} else if string(options.Args.SubAction) == IgmpLeaveKey {
+		subActionVal = pb.SubActionTypes_LEAVE
+	}
+
+	igmpReq := pb.IgmpRequest{
+		OnuReq:       &req,
+		SubActionVal: subActionVal,
+	}
+	res, err := client.GetONU(ctx, igmpReq.OnuReq)
+	if err != nil {
+		log.WithFields(log.Fields{
+			"SerialNumber": options.Args.OnuSn,
+		}).Errorf("Cannot not get details on ONU error: %v", err)
+	}
+	log.WithFields(log.Fields{
+		"SerialNumber": igmpReq.OnuReq.SerialNumber,
+	}).Debugf("ONU has indentified : %s", res)
+
+	igmpRes, igmpErr := client.ChangeIgmpState(ctx, &igmpReq)
+	if igmpErr != nil {
+		log.WithFields(log.Fields{
+			"SubAction": options.Args.SubAction,
+		}).Errorf("Could not process Action: error: %v", igmpErr)
+	} else {
+		log.WithFields(log.Fields{
+			"SubAction": options.Args.SubAction,
+		}).Debugf("igmp state has been changed with response: %s",
+			igmpRes.Message)
+	}
+
+	return nil
+}
+
 func (onuSn *OnuSnString) Complete(match string) []flags.Completion {
 	client, conn := connect()
 	defer conn.Close()