[SEBA-434] Replacing omci-sim with omci-lib-go
Change-Id: I499afc9ec49bb483467ea93bd6ce3077dd0ccc6e
diff --git a/internal/bbsim/alarmsim/alarmsim.go b/internal/bbsim/alarmsim/alarmsim.go
index cbb51da..6c6a290 100644
--- a/internal/bbsim/alarmsim/alarmsim.go
+++ b/internal/bbsim/alarmsim/alarmsim.go
@@ -17,17 +17,14 @@
package alarmsim
import (
- "context"
"fmt"
+ "github.com/opencord/bbsim/internal/bbsim/types"
"strconv"
"github.com/opencord/bbsim/internal/common"
"github.com/opencord/bbsim/api/bbsim"
- "github.com/opencord/bbsim/internal/bbsim/devices"
"github.com/opencord/voltha-protos/v4/go/openolt"
- "google.golang.org/grpc/codes"
- "google.golang.org/grpc/status"
)
func AlarmNameToEnum(name string) (bbsim.AlarmType_Types, error) {
@@ -54,9 +51,8 @@
}
// BuildOnuAlarmIndication function forms openolt alarmIndication as per ONUAlarmRequest
-func BuildOnuAlarmIndication(req *bbsim.ONUAlarmRequest, o *devices.OltDevice) (*openolt.AlarmIndication, error) {
+func BuildOnuAlarmIndication(req *bbsim.ONUAlarmRequest, onuID uint32, ponPortID uint32) (*openolt.AlarmIndication, error) {
var alarm *openolt.AlarmIndication
- var onu *devices.Onu
var err error
alarmType, err := AlarmNameToEnum(req.AlarmType)
@@ -64,37 +60,29 @@
return nil, err
}
- if alarmType != bbsim.AlarmType_LOS {
- // No ONU Id for LOS
- onu, err = o.FindOnuBySn(req.SerialNumber)
- if err != nil {
- return nil, err
- }
- }
-
switch alarmType {
case bbsim.AlarmType_DYING_GASP:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_DyingGaspInd{DyingGaspInd: &openolt.DyingGaspIndication{
Status: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
}},
}
case bbsim.AlarmType_ONU_STARTUP_FAILURE:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuStartupFailInd{OnuStartupFailInd: &openolt.OnuStartupFailureIndication{
Status: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
}},
}
case bbsim.AlarmType_ONU_SIGNAL_DEGRADE:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuSignalDegradeInd{OnuSignalDegradeInd: &openolt.OnuSignalDegradeIndication{
Status: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
InverseBitErrorRate: uint32(extractInt(req.Parameters, "InverseBitErrorRate", 0)),
}},
}
@@ -102,8 +90,8 @@
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuSignalsFailInd{OnuSignalsFailInd: &openolt.OnuSignalsFailureIndication{
Status: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
InverseBitErrorRate: uint32(extractInt(req.Parameters, "InverseBitErrorRate", 0)),
}},
}
@@ -111,8 +99,8 @@
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuDriftOfWindowInd{OnuDriftOfWindowInd: &openolt.OnuDriftOfWindowIndication{
Status: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
Drift: uint32(extractInt(req.Parameters, "Drift", 0)),
NewEqd: uint32(extractInt(req.Parameters, "NewEqd", 0)),
}},
@@ -121,47 +109,47 @@
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuLossOmciInd{OnuLossOmciInd: &openolt.OnuLossOfOmciChannelIndication{
Status: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
}},
}
case bbsim.AlarmType_ONU_TRANSMISSION_INTERFERENCE_WARNING:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuTiwiInd{OnuTiwiInd: &openolt.OnuTransmissionInterferenceWarning{
Status: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
Drift: uint32(extractInt(req.Parameters, "Drift", 0)),
}},
}
case bbsim.AlarmType_ONU_ACTIVATION_FAILURE:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuActivationFailInd{OnuActivationFailInd: &openolt.OnuActivationFailureIndication{
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
FailReason: uint32(extractInt(req.Parameters, "FailReason", 0)),
}},
}
case bbsim.AlarmType_ONU_PROCESSING_ERROR:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuProcessingErrorInd{OnuProcessingErrorInd: &openolt.OnuProcessingErrorIndication{
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
}},
}
case bbsim.AlarmType_ONU_LOSS_OF_KEY_SYNC_FAILURE:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuLossOfSyncFailInd{OnuLossOfSyncFailInd: &openolt.OnuLossOfKeySyncFailureIndication{
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
Status: req.Status,
}},
}
case bbsim.AlarmType_ONU_ITU_PON_STATS:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuItuPonStatsInd{OnuItuPonStatsInd: &openolt.OnuItuPonStatsIndication{
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
Stats: &openolt.OnuItuPonStatsIndication_RdiErrorInd{
RdiErrorInd: &openolt.RdiErrorIndication{
RdiErrorCount: uint64(extractInt(req.Parameters, "RdiErrors", 0)),
@@ -174,48 +162,48 @@
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
LosStatus: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
}},
}
case bbsim.AlarmType_ONU_ALARM_LOB:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
LobStatus: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
}},
}
case bbsim.AlarmType_ONU_ALARM_LOPC_MISS:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
LopcMissStatus: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
}},
}
case bbsim.AlarmType_ONU_ALARM_LOPC_MIC_ERROR:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
LopcMicErrorStatus: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
}},
}
case bbsim.AlarmType_ONU_ALARM_LOFI:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
LofiStatus: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
}},
}
case bbsim.AlarmType_ONU_ALARM_LOAMI:
alarm = &openolt.AlarmIndication{
Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
LoamiStatus: req.Status,
- OnuId: onu.ID,
- IntfId: onu.PonPortID,
+ OnuId: onuID,
+ IntfId: ponPortID,
}},
}
default:
@@ -226,70 +214,18 @@
}
// SimulateOnuAlarm accept request for Onu alarms and send proper alarmIndication to openolt stream
-func SimulateOnuAlarm(ctx context.Context, req *bbsim.ONUAlarmRequest, o *devices.OltDevice) error {
- alarmIndication, err := BuildOnuAlarmIndication(req, o)
+func SimulateOnuAlarm(req *bbsim.ONUAlarmRequest, onuID uint32, ponPortID uint32, channel chan types.Message) error {
+ alarmIndication, err := BuildOnuAlarmIndication(req, onuID, ponPortID)
if err != nil {
return err
}
- err = o.SendAlarmIndication(ctx, alarmIndication)
- if err != nil {
- return err
+ msg := types.Message{
+ Type: types.AlarmIndication,
+ Data: alarmIndication,
}
- return nil
-}
-
-// IsPonPortPresentInOlt verifies if given Pon port is present in olt
-func IsPonPortPresentInOlt(PonPort uint32) bool {
- o := devices.GetOLT()
- for _, intf := range o.Pons {
- if intf.ID == PonPort {
- return true
- }
- }
- return false
-}
-
-// IsNniPortPresentInOlt verifies if given nni port is present in olt
-func IsNniPortPresentInOlt(nniPort uint32) bool {
- o := devices.GetOLT()
- for _, intf := range o.Nnis {
- if intf.ID == nniPort {
- return true
- }
- }
- return false
-}
-
-// SimulateOltAlarm accept request for Olt alarms and send proper alarmIndication to openolt stream
-func SimulateOltAlarm(ctx context.Context, req *bbsim.OLTAlarmRequest, o *devices.OltDevice) error {
- var alarmIndication *openolt.AlarmIndication
- var err error
-
- //check if its a valid port id
- switch req.InterfaceType {
- case "nni":
- if !IsNniPortPresentInOlt(uint32(req.InterfaceID)) {
- return status.Errorf(codes.NotFound, strconv.Itoa(int(req.InterfaceID))+" NNI not present in olt")
- }
-
- case "pon":
- if !IsPonPortPresentInOlt(uint32(req.InterfaceID)) {
- return status.Errorf(codes.NotFound, strconv.Itoa(int(req.InterfaceID))+" PON not present in olt")
- }
- }
- alarmIndication = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_LosInd{LosInd: &openolt.LosIndication{
- Status: req.Status,
- IntfId: devices.InterfaceIDToPortNo(req.InterfaceID, req.InterfaceType),
- }},
- }
-
- err = o.SendAlarmIndication(ctx, alarmIndication)
- if err != nil {
- return err
- }
+ channel <- msg
return nil
}
diff --git a/internal/bbsim/api/grpc_api_server.go b/internal/bbsim/api/grpc_api_server.go
index 84d3478..5fd6392 100644
--- a/internal/bbsim/api/grpc_api_server.go
+++ b/internal/bbsim/api/grpc_api_server.go
@@ -23,7 +23,6 @@
"time"
"github.com/opencord/bbsim/api/bbsim"
- "github.com/opencord/bbsim/internal/bbsim/alarmsim"
"github.com/opencord/bbsim/internal/bbsim/devices"
"github.com/opencord/bbsim/internal/common"
log "github.com/sirupsen/logrus"
@@ -193,12 +192,22 @@
func (s BBSimServer) SetOnuAlarmIndication(ctx context.Context, req *bbsim.ONUAlarmRequest) (*bbsim.Response, error) {
o := devices.GetOLT()
- err := alarmsim.SimulateOnuAlarm(ctx, req, o)
+
+ res := &bbsim.Response{}
+
+ onu, err := o.FindOnuBySn(req.SerialNumber)
if err != nil {
+ res.StatusCode = int32(codes.NotFound)
+ res.Message = err.Error()
return nil, err
}
- res := &bbsim.Response{}
+ if err := onu.SetAlarm(req.AlarmType, req.Status); err != nil {
+ res.StatusCode = int32(codes.Internal)
+ res.Message = err.Error()
+ return nil, err
+ }
+
res.StatusCode = int32(codes.OK)
res.Message = fmt.Sprintf("Onu Alarm Indication Sent.")
return res, nil
@@ -207,12 +216,14 @@
// SetOltAlarmIndication generates OLT Alarms for LOS
func (s BBSimServer) SetOltAlarmIndication(ctx context.Context, req *bbsim.OLTAlarmRequest) (*bbsim.Response, error) {
o := devices.GetOLT()
- err := alarmsim.SimulateOltAlarm(ctx, req, o)
- if err != nil {
+ res := &bbsim.Response{}
+
+ if err := o.SetAlarm(req.InterfaceID, req.InterfaceType, req.Status); err != nil {
+ res.StatusCode = int32(codes.Internal)
+ res.Message = err.Error()
return nil, err
}
- res := &bbsim.Response{}
res.StatusCode = int32(codes.OK)
res.Message = fmt.Sprintf("Olt Alarm Indication Sent.")
return res, nil
diff --git a/internal/bbsim/api/onus_handler.go b/internal/bbsim/api/onus_handler.go
index 43b624f..2533fa3 100644
--- a/internal/bbsim/api/onus_handler.go
+++ b/internal/bbsim/api/onus_handler.go
@@ -19,10 +19,10 @@
import (
"context"
"fmt"
+ "github.com/opencord/bbsim/internal/bbsim/types"
"github.com/opencord/voltha-protos/v4/go/openolt"
"github.com/opencord/bbsim/api/bbsim"
- "github.com/opencord/bbsim/internal/bbsim/alarmsim"
"github.com/opencord/bbsim/internal/bbsim/devices"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
@@ -270,7 +270,7 @@
"Service": service.Name,
}).Debugf("Sending %s event on Service %s", event, service.Name)
- if err := service.IGMPState.Event(event, devices.IgmpMessage{GroupAddress: req.GroupAddress}); err != nil {
+ if err := service.IGMPState.Event(event, types.IgmpMessage{GroupAddress: req.GroupAddress}); err != nil {
logger.WithFields(log.Fields{
"OnuId": onu.ID,
"IntfId": onu.PonPortID,
@@ -452,64 +452,13 @@
func handlePoweronONU(onu *devices.Onu) (*bbsim.Response, error) {
res := &bbsim.Response{}
- olt := devices.GetOLT()
- intitalState := onu.InternalState.Current()
- if onu.InternalState.Current() == "created" || onu.InternalState.Current() == "disabled" {
- if err := onu.InternalState.Event("initialize"); err != nil {
- logger.WithFields(log.Fields{
- "OnuId": onu.ID,
- "IntfId": onu.PonPortID,
- "OnuSn": onu.Sn(),
- }).Errorf("Cannot poweron ONU: %s", err.Error())
- res.StatusCode = int32(codes.FailedPrecondition)
- res.Message = err.Error()
- return res, err
- }
- }
- losReq := bbsim.ONUAlarmRequest{
- AlarmType: "ONU_ALARM_LOS",
- SerialNumber: onu.Sn(),
- Status: "off",
- }
-
- if err := alarmsim.SimulateOnuAlarm(context.TODO(), &losReq, olt); err != nil {
- logger.WithFields(log.Fields{
- "OnuId": onu.ID,
- "IntfId": onu.PonPortID,
- "OnuSn": onu.Sn(),
- }).Errorf("Cannot send LOS: %s", err.Error())
+ if err := onu.HandlePowerOnONU(); err != nil {
res.StatusCode = int32(codes.FailedPrecondition)
res.Message = err.Error()
return res, err
}
- if err := onu.InternalState.Event("discover"); err != nil {
- logger.WithFields(log.Fields{
- "OnuId": onu.ID,
- "IntfId": onu.PonPortID,
- "OnuSn": onu.Sn(),
- }).Errorf("Cannot poweron ONU: %s", err.Error())
- res.StatusCode = int32(codes.FailedPrecondition)
- res.Message = err.Error()
- return res, err
- }
- // move onu directly to enable state only when its a powercycle case
- // in case of first time onu poweron onu will be moved to enable on
- // receiving ActivateOnu request from openolt adapter
- if intitalState == "disabled" {
- if err := onu.InternalState.Event("enable"); err != nil {
- logger.WithFields(log.Fields{
- "OnuId": onu.ID,
- "IntfId": onu.PonPortID,
- "OnuSn": onu.Sn(),
- }).Errorf("Cannot enable ONU: %s", err.Error())
- res.StatusCode = int32(codes.FailedPrecondition)
- res.Message = err.Error()
- return res, err
- }
- }
-
res.StatusCode = int32(codes.OK)
res.Message = fmt.Sprintf("ONU %s successfully powered on.", onu.Sn())
@@ -518,50 +467,8 @@
func handleShutdownONU(onu *devices.Onu) (*bbsim.Response, error) {
res := &bbsim.Response{}
- olt := devices.GetOLT()
- dyingGasp := bbsim.ONUAlarmRequest{
- AlarmType: "DYING_GASP",
- SerialNumber: onu.Sn(),
- Status: "on",
- }
-
- if err := alarmsim.SimulateOnuAlarm(context.TODO(), &dyingGasp, olt); err != nil {
- logger.WithFields(log.Fields{
- "OnuId": onu.ID,
- "IntfId": onu.PonPortID,
- "OnuSn": onu.Sn(),
- }).Errorf("Cannot send Dying Gasp: %s", err.Error())
- res.StatusCode = int32(codes.FailedPrecondition)
- res.Message = err.Error()
- return res, err
- }
-
- losReq := bbsim.ONUAlarmRequest{
- AlarmType: "ONU_ALARM_LOS",
- SerialNumber: onu.Sn(),
- Status: "on",
- }
-
- if err := alarmsim.SimulateOnuAlarm(context.TODO(), &losReq, olt); err != nil {
- logger.WithFields(log.Fields{
- "OnuId": onu.ID,
- "IntfId": onu.PonPortID,
- "OnuSn": onu.Sn(),
- }).Errorf("Cannot send LOS: %s", err.Error())
- res.StatusCode = int32(codes.FailedPrecondition)
- res.Message = err.Error()
- return res, err
- }
-
- // TODO if it's the last ONU on the PON, then send a PON LOS
-
- if err := onu.InternalState.Event("disable"); err != nil {
- logger.WithFields(log.Fields{
- "OnuId": onu.ID,
- "IntfId": onu.PonPortID,
- "OnuSn": onu.Sn(),
- }).Errorf("Cannot shutdown ONU: %s", err.Error())
+ if err := onu.HandleShutdownONU(); err != nil {
res.StatusCode = int32(codes.FailedPrecondition)
res.Message = err.Error()
return res, err
diff --git a/internal/bbsim/devices/olt.go b/internal/bbsim/devices/olt.go
index 9e26ad2..6540a56 100644
--- a/internal/bbsim/devices/olt.go
+++ b/internal/bbsim/devices/olt.go
@@ -21,8 +21,10 @@
"encoding/hex"
"fmt"
"github.com/opencord/bbsim/internal/bbsim/responders/dhcp"
+ "github.com/opencord/bbsim/internal/bbsim/types"
"github.com/opencord/voltha-protos/v4/go/ext/config"
"net"
+ "strconv"
"sync"
"time"
@@ -31,7 +33,6 @@
"github.com/looplab/fsm"
"github.com/opencord/bbsim/internal/bbsim/packetHandlers"
"github.com/opencord/bbsim/internal/common"
- omcisim "github.com/opencord/omci-sim"
common_protos "github.com/opencord/voltha-protos/v4/go/common"
"github.com/opencord/voltha-protos/v4/go/openolt"
"github.com/opencord/voltha-protos/v4/go/tech_profile"
@@ -57,7 +58,7 @@
NumPon int
NumOnuPerPon int
InternalState *fsm.FSM
- channel chan Message
+ channel chan types.Message
dhcpServer dhcp.DHCPServerIf
Flows sync.Map
Delay int
@@ -230,7 +231,7 @@
}
// create new channel for processOltMessages Go routine
- o.channel = make(chan Message)
+ o.channel = make(chan types.Message)
// FIXME we are assuming we have only one NNI
if o.Nnis[0] != nil {
@@ -272,10 +273,10 @@
for _, pon := range o.Pons {
if pon.InternalState.Current() == "enabled" {
// disable PONs
- msg := Message{
- Type: PonIndication,
- Data: PonIndicationMessage{
- OperState: DOWN,
+ msg := types.Message{
+ Type: types.PonIndication,
+ Data: types.PonIndicationMessage{
+ OperState: types.DOWN,
PonPortID: pon.ID,
},
}
@@ -388,35 +389,33 @@
go o.processOltMessages(o.enableContext, stream, &wg)
// enable the OLT
- oltMsg := Message{
- Type: OltIndication,
- Data: OltIndicationMessage{
- OperState: UP,
+ oltMsg := types.Message{
+ Type: types.OltIndication,
+ Data: types.OltIndicationMessage{
+ OperState: types.UP,
},
}
o.channel <- oltMsg
// send NNI Port Indications
for _, nni := range o.Nnis {
- msg := Message{
- Type: NniIndication,
- Data: NniIndicationMessage{
- OperState: UP,
+ msg := types.Message{
+ Type: types.NniIndication,
+ Data: types.NniIndicationMessage{
+ OperState: types.UP,
NniPortID: nni.ID,
},
}
o.channel <- msg
}
- go o.processOmciMessages(o.enableContext, stream, &wg)
-
if rebootFlag {
for _, pon := range o.Pons {
if pon.InternalState.Current() == "disabled" {
- msg := Message{
- Type: PonIndication,
- Data: PonIndicationMessage{
- OperState: UP,
+ msg := types.Message{
+ Type: types.PonIndication,
+ Data: types.PonIndicationMessage{
+ OperState: types.UP,
PonPortID: pon.ID,
},
}
@@ -431,10 +430,10 @@
if o.ControlledActivation == Default || o.ControlledActivation == OnlyONU {
// send PON Port indications
for _, pon := range o.Pons {
- msg := Message{
- Type: PonIndication,
- Data: PonIndicationMessage{
- OperState: UP,
+ msg := types.Message{
+ Type: types.PonIndication,
+ Data: types.PonIndicationMessage{
+ OperState: types.UP,
PonPortID: pon.ID,
},
}
@@ -453,43 +452,6 @@
wg.Wait()
}
-func (o *OltDevice) processOmciMessages(ctx context.Context, stream openolt.Openolt_EnableIndicationServer, wg *sync.WaitGroup) {
- ch := omcisim.GetChannel()
-
- oltLogger.Debug("Starting OMCI Indication Channel")
-
-loop:
- for {
- select {
- case <-ctx.Done():
- oltLogger.Debug("OMCI processing canceled via context")
- break loop
- case message, ok := <-ch:
- if !ok || ctx.Err() != nil {
- oltLogger.Debug("OMCI processing canceled via channel close")
- break loop
- }
-
- oltLogger.WithFields(log.Fields{
- "messageType": message.Type,
- "OnuId": message.Data.OnuId,
- "IntfId": message.Data.IntfId,
- }).Debug("Received message on OMCI Sim channel")
-
- onuId := message.Data.OnuId
- intfId := message.Data.IntfId
- onu, err := o.FindOnuById(intfId, onuId)
- if err != nil {
- oltLogger.Errorf("Failed to find onu: %v", err)
- continue
- }
- go onu.processOmciMessage(message, stream)
- }
- }
-
- wg.Done()
-}
-
func (o *OltDevice) periodicPortStats(ctx context.Context) {
var portStats *openolt.PortStatistics
for {
@@ -525,6 +487,55 @@
// Helpers method
+func (o *OltDevice) SetAlarm(interfaceId uint32, interfaceType string, alarmStatus string) error {
+
+ switch interfaceType {
+ case "nni":
+ if !o.HasNni(interfaceId) {
+ return status.Errorf(codes.NotFound, strconv.Itoa(int(interfaceId))+" NNI not present in olt")
+ }
+
+ case "pon":
+ if !o.HasPon(interfaceId) {
+ return status.Errorf(codes.NotFound, strconv.Itoa(int(interfaceId))+" PON not present in olt")
+ }
+ }
+
+ alarmIndication := &openolt.AlarmIndication{
+ Data: &openolt.AlarmIndication_LosInd{LosInd: &openolt.LosIndication{
+ Status: alarmStatus,
+ IntfId: InterfaceIDToPortNo(interfaceId, interfaceType),
+ }},
+ }
+
+ msg := types.Message{
+ Type: types.AlarmIndication,
+ Data: alarmIndication,
+ }
+
+ o.channel <- msg
+
+ return nil
+}
+
+func (o *OltDevice) HasNni(id uint32) bool {
+ for _, intf := range o.Nnis {
+ if intf.ID == id {
+ return true
+ }
+ }
+ return false
+}
+
+func (o *OltDevice) HasPon(id uint32) bool {
+ for _, intf := range o.Pons {
+ if intf.ID == id {
+ return true
+ }
+ }
+ return false
+}
+
func (o *OltDevice) GetPonById(id uint32) (*PonPort, error) {
for _, pon := range o.Pons {
if pon.ID == id {
@@ -555,7 +566,7 @@
}).Debug("Sent Indication_AlarmInd")
}
-func (o *OltDevice) sendOltIndication(msg OltIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
+func (o *OltDevice) sendOltIndication(msg types.OltIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: msg.OperState.String()}}
if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
oltLogger.Errorf("Failed to send Indication_OltInd: %v", err)
@@ -567,9 +578,9 @@
}).Debug("Sent Indication_OltInd")
}
-func (o *OltDevice) sendNniIndication(msg NniIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
+func (o *OltDevice) sendNniIndication(msg types.NniIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
nni, _ := o.getNniById(msg.NniPortID)
- if msg.OperState == UP {
+ if msg.OperState == types.UP {
if err := nni.OperState.Event("enable"); err != nil {
log.WithFields(log.Fields{
"Type": nni.Type,
@@ -577,7 +588,7 @@
"OperState": nni.OperState.Current(),
}).Errorf("Can't move NNI Port to enabled state: %v", err)
}
- } else if msg.OperState == DOWN {
+ } else if msg.OperState == types.DOWN {
if err := nni.OperState.Event("disable"); err != nil {
log.WithFields(log.Fields{
"Type": nni.Type,
@@ -685,26 +696,26 @@
}).Trace("Received message")
switch message.Type {
- case OltIndication:
- msg, _ := message.Data.(OltIndicationMessage)
- if msg.OperState == UP {
+ case types.OltIndication:
+ msg, _ := message.Data.(types.OltIndicationMessage)
+ if msg.OperState == types.UP {
_ = o.InternalState.Event("enable")
_ = o.OperState.Event("enable")
- } else if msg.OperState == DOWN {
+ } else if msg.OperState == types.DOWN {
_ = o.InternalState.Event("disable")
_ = o.OperState.Event("disable")
}
o.sendOltIndication(msg, stream)
- case AlarmIndication:
+ case types.AlarmIndication:
alarmInd, _ := message.Data.(*openolt.AlarmIndication)
o.sendAlarmIndication(alarmInd, stream)
- case NniIndication:
- msg, _ := message.Data.(NniIndicationMessage)
+ case types.NniIndication:
+ msg, _ := message.Data.(types.NniIndicationMessage)
o.sendNniIndication(msg, stream)
- case PonIndication:
- msg, _ := message.Data.(PonIndicationMessage)
+ case types.PonIndication:
+ msg, _ := message.Data.(types.PonIndicationMessage)
pon, _ := o.GetPonById(msg.PonPortID)
- if msg.OperState == UP {
+ if msg.OperState == types.UP {
if err := pon.OperState.Event("enable"); err != nil {
oltLogger.WithFields(log.Fields{
"IntfId": msg.PonPortID,
@@ -717,7 +728,7 @@
"Err": err,
}).Error("Can't Enable Internal state for PON Port")
}
- } else if msg.OperState == DOWN {
+ } else if msg.OperState == types.DOWN {
if err := pon.OperState.Event("disable"); err != nil {
oltLogger.WithFields(log.Fields{
"IntfId": msg.PonPortID,
@@ -873,10 +884,10 @@
for _, pon := range o.Pons {
if pon.InternalState.Current() == "enabled" {
// disable PONs
- msg := Message{
- Type: PonIndication,
- Data: PonIndicationMessage{
- OperState: DOWN,
+ msg := types.Message{
+ Type: types.PonIndication,
+ Data: types.PonIndicationMessage{
+ OperState: types.DOWN,
PonPortID: pon.ID,
},
}
@@ -888,10 +899,10 @@
// The reason for that is in-band management
// disable OLT
- oltMsg := Message{
- Type: OltIndication,
- Data: OltIndicationMessage{
- OperState: DOWN,
+ oltMsg := types.Message{
+ Type: types.OltIndication,
+ Data: types.OltIndicationMessage{
+ OperState: types.DOWN,
},
}
o.channel <- oltMsg
@@ -903,10 +914,10 @@
ponID := intf.GetIntfId()
pon, _ := o.GetPonById(intf.IntfId)
- msg := Message{
- Type: PonIndication,
- Data: PonIndicationMessage{
- OperState: DOWN,
+ msg := types.Message{
+ Type: types.PonIndication,
+ Data: types.PonIndicationMessage{
+ OperState: types.DOWN,
PonPortID: ponID,
},
}
@@ -914,8 +925,8 @@
for _, onu := range pon.Onus {
- onuIndication := OnuIndicationMessage{
- OperState: DOWN,
+ onuIndication := types.OnuIndicationMessage{
+ OperState: types.DOWN,
PonPortID: ponID,
OnuID: onu.ID,
OnuSN: onu.SerialNumber,
@@ -939,10 +950,10 @@
ponID := intf.GetIntfId()
pon, _ := o.GetPonById(intf.IntfId)
- msg := Message{
- Type: PonIndication,
- Data: PonIndicationMessage{
- OperState: UP,
+ msg := types.Message{
+ Type: types.PonIndication,
+ Data: types.PonIndicationMessage{
+ OperState: types.UP,
PonPortID: ponID,
},
}
@@ -950,8 +961,8 @@
for _, onu := range pon.Onus {
- onuIndication := OnuIndicationMessage{
- OperState: UP,
+ onuIndication := types.OnuIndicationMessage{
+ OperState: types.UP,
PonPortID: ponID,
OnuID: onu.ID,
OnuSN: onu.SerialNumber,
@@ -1030,9 +1041,9 @@
}
}
- msg := Message{
- Type: FlowAdd,
- Data: OnuFlowUpdateMessage{
+ msg := types.Message{
+ Type: types.FlowAdd,
+ Data: types.OnuFlowUpdateMessage{
PonPortID: pon.ID,
OnuID: onu.ID,
Flow: flow,
@@ -1107,9 +1118,9 @@
return nil, err
}
- msg := Message{
- Type: FlowRemoved,
- Data: OnuFlowUpdateMessage{
+ msg := types.Message{
+ Type: types.FlowRemoved,
+ Data: types.OnuFlowUpdateMessage{
Flow: flow,
},
}
@@ -1193,12 +1204,12 @@
"OnuId": onu.ID,
"OnuSn": onu.Sn(),
}).Tracef("Received OmciMsgOut")
- msg := Message{
- Type: OMCI,
- Data: OmciMessage{
+ msg := types.Message{
+ Type: types.OMCI,
+ Data: types.OmciMessage{
OnuSN: onu.SerialNumber,
OnuID: onu.ID,
- omciMsg: omci_msg,
+ OmciMsg: omci_msg,
},
}
onu.Channel <- msg
@@ -1254,9 +1265,9 @@
return new(openolt.Empty), nil
}
- msg := Message{
- Type: OnuPacketOut,
- Data: OnuPacketMessage{
+ msg := types.Message{
+ Type: types.OnuPacketOut,
+ Data: types.OnuPacketMessage{
IntfId: onuPkt.IntfId,
OnuId: onuPkt.OnuId,
Packet: rawpkt,
@@ -1291,20 +1302,20 @@
publishEvent("OLT-reenable-received", -1, -1, "")
// enable OLT
- oltMsg := Message{
- Type: OltIndication,
- Data: OltIndicationMessage{
- OperState: UP,
+ oltMsg := types.Message{
+ Type: types.OltIndication,
+ Data: types.OltIndicationMessage{
+ OperState: types.UP,
},
}
o.channel <- oltMsg
for _, pon := range o.Pons {
if pon.InternalState.Current() == "disabled" {
- msg := Message{
- Type: PonIndication,
- Data: PonIndicationMessage{
- OperState: UP,
+ msg := types.Message{
+ Type: types.PonIndication,
+ Data: types.PonIndicationMessage{
+ OperState: types.UP,
PonPortID: pon.ID,
},
}
@@ -1397,17 +1408,6 @@
return new(openolt.Empty), nil
}
-// assumes caller has properly formulated an openolt.AlarmIndication
-func (o *OltDevice) SendAlarmIndication(context context.Context, ind *openolt.AlarmIndication) error {
- msg := Message{
- Type: AlarmIndication,
- Data: ind,
- }
-
- o.channel <- msg
- return nil
-}
-
func (o *OltDevice) PerformGroupOperation(ctx context.Context, group *openolt.Group) (*openolt.Empty, error) {
oltLogger.WithFields(log.Fields{
"GroupId": group.GroupId,
diff --git a/internal/bbsim/devices/olt_test.go b/internal/bbsim/devices/olt_test.go
index 0081ffa..154942b 100644
--- a/internal/bbsim/devices/olt_test.go
+++ b/internal/bbsim/devices/olt_test.go
@@ -17,6 +17,7 @@
package devices
import (
+ "github.com/opencord/bbsim/internal/bbsim/types"
"github.com/opencord/bbsim/internal/common"
"net"
"testing"
@@ -202,7 +203,7 @@
FlowId: 64,
Classifier: &openolt.Classifier{},
}
- msg1 := OnuFlowUpdateMessage{
+ msg1 := types.OnuFlowUpdateMessage{
OnuID: onu1.ID,
PonPortID: onu1.PonPortID,
Flow: &flow1,
@@ -214,7 +215,7 @@
FlowId: 72,
Classifier: &openolt.Classifier{},
}
- msg2 := OnuFlowUpdateMessage{
+ msg2 := types.OnuFlowUpdateMessage{
OnuID: onu2.ID,
PonPortID: onu2.PonPortID,
Flow: &flow2,
diff --git a/internal/bbsim/devices/onu.go b/internal/bbsim/devices/onu.go
index b85c804..822ec6b 100644
--- a/internal/bbsim/devices/onu.go
+++ b/internal/bbsim/devices/onu.go
@@ -20,20 +20,24 @@
"context"
"encoding/hex"
"fmt"
+ pb "github.com/opencord/bbsim/api/bbsim"
+ "github.com/opencord/bbsim/internal/bbsim/alarmsim"
+ bbsim "github.com/opencord/bbsim/internal/bbsim/types"
+ me "github.com/opencord/omci-lib-go/generated"
+ "strconv"
+
"github.com/opencord/bbsim/internal/bbsim/packetHandlers"
"github.com/opencord/bbsim/internal/bbsim/responders/dhcp"
"github.com/opencord/bbsim/internal/bbsim/responders/eapol"
"net"
-
"time"
- "github.com/cboling/omci"
"github.com/google/gopacket/layers"
"github.com/jpillora/backoff"
"github.com/looplab/fsm"
"github.com/opencord/bbsim/internal/common"
omcilib "github.com/opencord/bbsim/internal/common/omci"
- omcisim "github.com/opencord/omci-sim"
+ "github.com/opencord/omci-lib-go"
"github.com/opencord/voltha-protos/v4/go/openolt"
"github.com/opencord/voltha-protos/v4/go/tech_profile"
log "github.com/sirupsen/logrus"
@@ -72,7 +76,7 @@
OperState *fsm.FSM
SerialNumber *openolt.SerialNumber
- Channel chan Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets
+ Channel chan bbsim.Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets
// OMCI params
tid uint16
@@ -143,7 +147,7 @@
},
"enter_initialized": func(e *fsm.Event) {
// create new channel for ProcessOnuMessages Go routine
- o.Channel = make(chan Message, 2048)
+ o.Channel = make(chan bbsim.Message, 2048)
if err := o.OperState.Event("enable"); err != nil {
onuLogger.WithFields(log.Fields{
@@ -159,22 +163,21 @@
}
},
"enter_discovered": func(e *fsm.Event) {
- msg := Message{
- Type: OnuDiscIndication,
- Data: OnuDiscIndicationMessage{
- Onu: &o,
- OperState: UP,
+ msg := bbsim.Message{
+ Type: bbsim.OnuDiscIndication,
+ Data: bbsim.OnuDiscIndicationMessage{
+ OperState: bbsim.UP,
},
}
o.Channel <- msg
},
"enter_enabled": func(event *fsm.Event) {
- msg := Message{
- Type: OnuIndication,
- Data: OnuIndicationMessage{
+ msg := bbsim.Message{
+ Type: bbsim.OnuIndication,
+ Data: bbsim.OnuIndicationMessage{
OnuSN: o.SerialNumber,
PonPortID: o.PonPortID,
- OperState: UP,
+ OperState: bbsim.UP,
},
}
o.Channel <- msg
@@ -201,12 +204,12 @@
}
// send the OnuIndication DOWN event
- msg := Message{
- Type: OnuIndication,
- Data: OnuIndicationMessage{
+ msg := bbsim.Message{
+ Type: bbsim.OnuIndication,
+ Data: bbsim.OnuIndicationMessage{
OnuSN: o.SerialNumber,
PonPortID: o.PonPortID,
- OperState: DOWN,
+ OperState: bbsim.DOWN,
},
}
o.Channel <- msg
@@ -223,14 +226,14 @@
},
// BBR states
"enter_eapol_flow_sent": func(e *fsm.Event) {
- msg := Message{
- Type: SendEapolFlow,
+ msg := bbsim.Message{
+ Type: bbsim.SendEapolFlow,
}
o.Channel <- msg
},
"enter_dhcp_flow_sent": func(e *fsm.Event) {
- msg := Message{
- Type: SendDhcpFlow,
+ msg := bbsim.Message{
+ Type: bbsim.SendDhcpFlow,
}
o.Channel <- msg
},
@@ -280,26 +283,45 @@
}).Tracef("Received message on ONU Channel")
switch message.Type {
- case OnuDiscIndication:
- msg, _ := message.Data.(OnuDiscIndicationMessage)
+ case bbsim.OnuDiscIndication:
+ msg, _ := message.Data.(bbsim.OnuDiscIndicationMessage)
// NOTE we need to slow down and send ONU Discovery Indication in batches to better emulate a real scenario
time.Sleep(o.DiscoveryDelay)
o.sendOnuDiscIndication(msg, stream)
- case OnuIndication:
- msg, _ := message.Data.(OnuIndicationMessage)
+ case bbsim.OnuIndication:
+ msg, _ := message.Data.(bbsim.OnuIndicationMessage)
o.sendOnuIndication(msg, stream)
- case OMCI:
- msg, _ := message.Data.(OmciMessage)
- o.handleOmciMessage(msg, stream)
- case FlowAdd:
- msg, _ := message.Data.(OnuFlowUpdateMessage)
+ case bbsim.OMCI:
+ msg, _ := message.Data.(bbsim.OmciMessage)
+ o.handleOmciRequest(msg, stream)
+ case bbsim.UniStatusAlarm:
+ msg, _ := message.Data.(bbsim.UniStatusAlarmMessage)
+ pkt := omcilib.CreateUniStatusAlarm(msg.AdminState, msg.EntityID)
+ if err := o.sendOmciIndication(pkt, 0, stream); err != nil {
+ onuLogger.WithFields(log.Fields{
+ "IntfId": o.PonPortID,
+ "SerialNumber": o.Sn(),
+ "omciPacket": pkt,
+ "adminState": msg.AdminState,
+ "entityID": msg.EntityID,
+ }).Errorf("failed-to-send-UNI-Link-Alarm: %v", err)
+ }
+ onuLogger.WithFields(log.Fields{
+ "IntfId": o.PonPortID,
+ "SerialNumber": o.Sn(),
+ "omciPacket": pkt,
+ "adminState": msg.AdminState,
+ "entityID": msg.EntityID,
+ }).Trace("UNI-Link-alarm-sent")
+ case bbsim.FlowAdd:
+ msg, _ := message.Data.(bbsim.OnuFlowUpdateMessage)
o.handleFlowAdd(msg)
- case FlowRemoved:
- msg, _ := message.Data.(OnuFlowUpdateMessage)
+ case bbsim.FlowRemoved:
+ msg, _ := message.Data.(bbsim.OnuFlowUpdateMessage)
o.handleFlowRemove(msg)
- case OnuPacketOut:
+ case bbsim.OnuPacketOut:
- msg, _ := message.Data.(OnuPacketMessage)
+ msg, _ := message.Data.(bbsim.OnuPacketMessage)
onuLogger.WithFields(log.Fields{
"IntfId": msg.IntfId,
@@ -333,11 +355,11 @@
}
}
- case OnuPacketIn:
+ case bbsim.OnuPacketIn:
// NOTE we only receive BBR packets here.
// Eapol.HandleNextPacket can handle both BBSim and BBr cases so the call is the same
// in the DHCP case VOLTHA only act as a proxy, the behaviour is completely different thus we have a dhcp.HandleNextBbrPacket
- msg, _ := message.Data.(OnuPacketMessage)
+ msg, _ := message.Data.(bbsim.OnuPacketMessage)
log.WithFields(log.Fields{
"IntfId": msg.IntfId,
@@ -351,12 +373,12 @@
_ = dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.DoneChannel, msg.Packet, client)
}
// BBR specific messages
- case OmciIndication:
- msg, _ := message.Data.(OmciIndicationMessage)
- o.handleOmci(msg, client)
- case SendEapolFlow:
+ case bbsim.OmciIndication:
+ msg, _ := message.Data.(bbsim.OmciIndicationMessage)
+ o.handleOmciResponse(msg, client)
+ case bbsim.SendEapolFlow:
o.sendEapolFlow(client)
- case SendDhcpFlow:
+ case bbsim.SendDhcpFlow:
o.sendDhcpFlow(client)
default:
onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
@@ -369,42 +391,6 @@
}).Debug("Stopped handling ONU Indication Channel")
}
-func (o *Onu) processOmciMessage(message omcisim.OmciChMessage, stream openolt.Openolt_EnableIndicationServer) {
- switch message.Type {
- case omcisim.UniLinkUp, omcisim.UniLinkDown:
- onuLogger.WithFields(log.Fields{
- "OnuId": message.Data.OnuId,
- "IntfId": message.Data.IntfId,
- "Type": message.Type,
- }).Debug("UNI Link Alarm")
- // TODO send to OLT
-
- omciInd := openolt.OmciIndication{
- IntfId: message.Data.IntfId,
- OnuId: message.Data.OnuId,
- Pkt: message.Packet,
- }
-
- omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
- if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
- onuLogger.WithFields(log.Fields{
- "IntfId": o.PonPortID,
- "SerialNumber": o.Sn(),
- "Type": message.Type,
- "omciPacket": omciInd.Pkt,
- }).Errorf("Failed to send UNI Link Alarm: %v", err)
- return
- }
-
- onuLogger.WithFields(log.Fields{
- "IntfId": o.PonPortID,
- "SerialNumber": o.Sn(),
- "Type": message.Type,
- "omciPacket": omciInd.Pkt,
- }).Debug("UNI Link alarm sent")
- }
-}
-
func (o Onu) NewSN(oltid int, intfid uint32, onuid uint32) *openolt.SerialNumber {
sn := new(openolt.SerialNumber)
@@ -416,10 +402,10 @@
return sn
}
-func (o *Onu) sendOnuDiscIndication(msg OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
+func (o *Onu) sendOnuDiscIndication(msg bbsim.OnuDiscIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
discoverData := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{
- IntfId: msg.Onu.PonPortID,
- SerialNumber: msg.Onu.SerialNumber,
+ IntfId: o.PonPortID,
+ SerialNumber: o.SerialNumber,
}}
if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil {
@@ -428,11 +414,11 @@
}
onuLogger.WithFields(log.Fields{
- "IntfId": msg.Onu.PonPortID,
- "OnuSn": msg.Onu.Sn(),
+ "IntfId": o.PonPortID,
+ "OnuSn": o.Sn(),
"OnuId": o.ID,
}).Debug("Sent Indication_OnuDiscInd")
- publishEvent("ONU-discovery-indication-sent", int32(msg.Onu.PonPortID), int32(o.ID), msg.Onu.Sn())
+ publishEvent("ONU-discovery-indication-sent", int32(o.PonPortID), int32(o.ID), o.Sn())
// after DiscoveryRetryDelay check if the state is the same and in case send a new OnuDiscIndication
go func(delay time.Duration) {
@@ -443,7 +429,7 @@
}(o.DiscoveryRetryDelay)
}
-func (o *Onu) sendOnuIndication(msg OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
+func (o *Onu) sendOnuIndication(msg bbsim.OnuIndicationMessage, stream openolt.Openolt_EnableIndicationServer) {
// NOTE voltha returns an ID, but if we use that ID then it complains:
// expected_onu_id: 1, received_onu_id: 1024, event: ONU-id-mismatch, can happen if both voltha and the olt rebooted
// so we're using the internal ID that is 1
@@ -471,17 +457,136 @@
}
-func (o *Onu) publishOmciEvent(msg OmciMessage) {
+func (o *Onu) HandleShutdownONU() error {
+
+ dyingGasp := pb.ONUAlarmRequest{
+ AlarmType: "DYING_GASP",
+ SerialNumber: o.Sn(),
+ Status: "on",
+ }
+
+ if err := alarmsim.SimulateOnuAlarm(&dyingGasp, o.ID, o.PonPortID, o.PonPort.Olt.channel); err != nil {
+ onuLogger.WithFields(log.Fields{
+ "OnuId": o.ID,
+ "IntfId": o.PonPortID,
+ "OnuSn": o.Sn(),
+ }).Errorf("Cannot send Dying Gasp: %s", err.Error())
+ return err
+ }
+
+ losReq := pb.ONUAlarmRequest{
+ AlarmType: "ONU_ALARM_LOS",
+ SerialNumber: o.Sn(),
+ Status: "on",
+ }
+
+ if err := alarmsim.SimulateOnuAlarm(&losReq, o.ID, o.PonPortID, o.PonPort.Olt.channel); err != nil {
+ onuLogger.WithFields(log.Fields{
+ "OnuId": o.ID,
+ "IntfId": o.PonPortID,
+ "OnuSn": o.Sn(),
+ }).Errorf("Cannot send LOS: %s", err.Error())
+
+ return err
+ }
+
+ // TODO if it's the last ONU on the PON, then send a PON LOS
+
+ if err := o.InternalState.Event("disable"); err != nil {
+ onuLogger.WithFields(log.Fields{
+ "OnuId": o.ID,
+ "IntfId": o.PonPortID,
+ "OnuSn": o.Sn(),
+ }).Errorf("Cannot shutdown ONU: %s", err.Error())
+ return err
+ }
+
+ return nil
+}
+
+func (o *Onu) HandlePowerOnONU() error {
+ intitalState := o.InternalState.Current()
+
+ // initialize the ONU
+ if intitalState == "created" || intitalState == "disabled" {
+ if err := o.InternalState.Event("initialize"); err != nil {
+ onuLogger.WithFields(log.Fields{
+ "OnuId": o.ID,
+ "IntfId": o.PonPortID,
+ "OnuSn": o.Sn(),
+ }).Errorf("Cannot poweron ONU: %s", err.Error())
+ return err
+ }
+ }
+
+ // turn off the LOS Alarm
+ losReq := pb.ONUAlarmRequest{
+ AlarmType: "ONU_ALARM_LOS",
+ SerialNumber: o.Sn(),
+ Status: "off",
+ }
+
+ if err := alarmsim.SimulateOnuAlarm(&losReq, o.ID, o.PonPortID, o.PonPort.Olt.channel); err != nil {
+ onuLogger.WithFields(log.Fields{
+ "OnuId": o.ID,
+ "IntfId": o.PonPortID,
+ "OnuSn": o.Sn(),
+ }).Errorf("Cannot send LOS: %s", err.Error())
+ return err
+ }
+
+ // Send a ONU Discovery indication
+ if err := o.InternalState.Event("discover"); err != nil {
+ onuLogger.WithFields(log.Fields{
+ "OnuId": o.ID,
+ "IntfId": o.PonPortID,
+ "OnuSn": o.Sn(),
+ }).Errorf("Cannot poweron ONU: %s", err.Error())
+ return err
+ }
+
+ // move o directly to enable state only when its a powercycle case
+ // in case of first time o poweron o will be moved to enable on
+ // receiving ActivateOnu request from openolt adapter
+ if intitalState == "disabled" {
+ if err := o.InternalState.Event("enable"); err != nil {
+ onuLogger.WithFields(log.Fields{
+ "OnuId": o.ID,
+ "IntfId": o.PonPortID,
+ "OnuSn": o.Sn(),
+ }).Errorf("Cannot enable ONU: %s", err.Error())
+ return err
+ }
+ }
+
+ return nil
+}
+
+func (o *Onu) SetAlarm(alarmType string, status string) error {
+ alarmReq := pb.ONUAlarmRequest{
+ AlarmType: alarmType,
+ SerialNumber: o.Sn(),
+ Status: status,
+ }
+
+ err := alarmsim.SimulateOnuAlarm(&alarmReq, o.ID, o.PonPortID, o.PonPort.Olt.channel)
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+func (o *Onu) publishOmciEvent(msg bbsim.OmciMessage) {
if olt.PublishEvents {
- _, _, msgType, _, _, _, err := omcisim.ParsePkt(HexDecode(msg.omciMsg.Pkt))
+ _, omciMsg, err := omcilib.ParseOpenOltOmciPacket(msg.OmciMsg.Pkt)
if err != nil {
log.Errorf("error in getting msgType %v", err)
return
}
- if msgType == omcisim.MibUpload {
+ if omciMsg.MessageType == omci.MibUploadRequestType {
o.seqNumber = 0
publishEvent("MIB-upload-received", int32(o.PonPortID), int32(o.ID), common.OnuSnToString(o.SerialNumber))
- } else if msgType == omcisim.MibUploadNext {
+ } else if omciMsg.MessageType == omci.MibUploadNextRequestType {
o.seqNumber++
if o.seqNumber > 290 {
publishEvent("MIB-upload-done", int32(o.PonPortID), int32(o.ID), common.OnuSnToString(o.SerialNumber))
@@ -491,8 +596,8 @@
}
// Create a TestResponse packet and send it
-func (o *Onu) sendTestResult(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) error {
- resp, err := omcilib.BuildTestResult(HexDecode(msg.omciMsg.Pkt))
+func (o *Onu) sendTestResult(msg bbsim.OmciMessage, stream openolt.Openolt_EnableIndicationServer) error {
+ resp, err := omcilib.BuildTestResult(msg.OmciMsg.Pkt)
if err != nil {
return err
}
@@ -504,12 +609,6 @@
omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
- onuLogger.WithFields(log.Fields{
- "IntfId": o.PonPortID,
- "SerialNumber": o.Sn(),
- "omciPacket": omciInd.Pkt,
- "msg": msg,
- }).Errorf("send TestResult omcisim indication failed: %v", err)
return err
}
onuLogger.WithFields(log.Fields{
@@ -521,57 +620,151 @@
return nil
}
-func (o *Onu) handleOmciMessage(msg OmciMessage, stream openolt.Openolt_EnableIndicationServer) {
+// handleOmciRequest is responsible to parse the OMCI packets received from the openolt adapter
+// and generate the appropriate response to it
+func (o *Onu) handleOmciRequest(msg bbsim.OmciMessage, stream openolt.Openolt_EnableIndicationServer) {
+
+ omciPkt, omciMsg, err := omcilib.ParseOpenOltOmciPacket(msg.OmciMsg.Pkt)
+ if err != nil {
+ log.WithFields(log.Fields{
+ "IntfId": o.PonPortID,
+ "SerialNumber": o.Sn(),
+ "omciPacket": msg.OmciMsg.Pkt,
+ }).Error("cannot-parse-OMCI-packet")
+ }
onuLogger.WithFields(log.Fields{
+ "omciMsgType": omciMsg.MessageType,
+ "transCorrId": strconv.FormatInt(int64(omciMsg.TransactionID), 16),
+ "DeviceIdent": omciMsg.DeviceIdentifier,
"IntfId": o.PonPortID,
"SerialNumber": o.Sn(),
- "omciPacket": msg.omciMsg.Pkt,
- }).Tracef("Received OMCI message")
+ }).Trace("omci-message-decoded")
+
+ var responsePkt []byte
+ switch omciMsg.MessageType {
+ case omci.MibResetRequestType:
+ responsePkt, _ = omcilib.CreateMibResetResponse(omciMsg.TransactionID)
+ case omci.MibUploadRequestType:
+ responsePkt, _ = omcilib.CreateMibUploadResponse(omciMsg.TransactionID)
+ case omci.MibUploadNextRequestType:
+ responsePkt, _ = omcilib.CreateMibUploadNextResponse(omciPkt, omciMsg)
+ case omci.GetRequestType:
+ responsePkt, _ = omcilib.CreateGetResponse(omciPkt, omciMsg)
+ case omci.SetRequestType:
+ responsePkt, _ = omcilib.CreateSetResponse(omciPkt, omciMsg)
+
+ msgObj, _ := omcilib.ParseSetRequest(omciPkt)
+ switch msgObj.EntityClass {
+ case me.PhysicalPathTerminationPointEthernetUniClassID:
+ // if we're Setting a PPTP state
+ // we need to send the appropriate alarm
+
+ if msgObj.EntityInstance == 257 {
+ // for now we're only caring about the first UNI
+ // NOTE that the EntityID for the UNI port is for now hardcoded in
+ // omci/mibpackets.go where the PhysicalPathTerminationPointEthernetUni
+ // are reported during the MIB Upload sequence
+ adminState := msgObj.Attributes["AdministrativeState"].(uint8)
+ msg := bbsim.Message{
+ Type: bbsim.UniStatusAlarm,
+ Data: bbsim.UniStatusAlarmMessage{
+ OnuSN: o.SerialNumber,
+ OnuID: o.ID,
+ AdminState: adminState,
+ EntityID: msgObj.EntityInstance,
+ },
+ }
+ o.Channel <- msg
+ }
+ }
+ case omci.CreateRequestType:
+ responsePkt, _ = omcilib.CreateCreateResponse(omciPkt, omciMsg)
+ case omci.DeleteRequestType:
+ responsePkt, _ = omcilib.CreateDeleteResponse(omciPkt, omciMsg)
+ case omci.RebootRequestType:
+
+ responsePkt, _ = omcilib.CreateRebootResponse(omciPkt, omciMsg)
+
+ // powercycle the ONU
+ go func() {
+ // we run this in a separate goroutine so that
+ // the RebootRequestResponse is sent to VOLTHA
+ onuLogger.WithFields(log.Fields{
+ "IntfId": o.PonPortID,
+ "SerialNumber": o.Sn(),
+ }).Debug("shutting-down-onu-for-omci-reboot")
+ _ = o.HandleShutdownONU()
+ time.Sleep(10 * time.Second)
+ onuLogger.WithFields(log.Fields{
+ "IntfId": o.PonPortID,
+ "SerialNumber": o.Sn(),
+ }).Debug("power-on-onu-for-omci-reboot")
+ _ = o.HandlePowerOnONU()
+ }()
+ case omci.TestRequestType:
+
+ // Test message is special, it requires sending two packets:
+ // first packet: TestResponse, says whether test was started successully, handled by omci-sim
+ // second packet, TestResult, reports the result of running the self-test
+ // TestResult can come some time after a TestResponse
+ // TODO: Implement some delay between the TestResponse and the TestResult
+ isTest, err := omcilib.IsTestRequest(msg.OmciMsg.Pkt)
+ if (err == nil) && (isTest) {
+ if sendErr := o.sendTestResult(msg, stream); sendErr != nil {
+ onuLogger.WithFields(log.Fields{
+ "IntfId": o.PonPortID,
+ "SerialNumber": o.Sn(),
+ "omciPacket": msg.OmciMsg.Pkt,
+ "msg": msg,
+ "err": sendErr,
+ }).Error("send-TestResult-indication-failed")
+ }
+ }
+
+ default:
+ log.WithFields(log.Fields{
+ "omciMsgType": omciMsg.MessageType,
+ "transCorrId": omciMsg.TransactionID,
+ "IntfId": o.PonPortID,
+ "SerialNumber": o.Sn(),
+ }).Warnf("OMCI-message-not-supported")
+ }
+
+ if responsePkt != nil {
+ if err := o.sendOmciIndication(responsePkt, omciMsg.TransactionID, stream); err != nil {
+ onuLogger.WithFields(log.Fields{
+ "IntfId": o.PonPortID,
+ "SerialNumber": o.Sn(),
+ "omciPacket": responsePkt,
+ "omciMsgType": omciMsg.MessageType,
+ "transCorrId": omciMsg.TransactionID,
+ }).Errorf("failed-to-send-omci-message: %v", err)
+ }
+ }
o.publishOmciEvent(msg)
+}
- var omciInd openolt.OmciIndication
- respPkt, err := omcisim.OmciSim(o.PonPort.Olt.ID, o.PonPortID, o.ID, HexDecode(msg.omciMsg.Pkt))
- if err != nil {
- onuLogger.WithFields(log.Fields{
- "IntfId": o.PonPortID,
- "SerialNumber": o.Sn(),
- "omciPacket": omciInd.Pkt,
- "msg": msg,
- }).Errorf("Error handling OMCI message %v", msg)
- return
+// sendOmciIndication takes an OMCI packet and sends it up to VOLTHA
+func (o *Onu) sendOmciIndication(responsePkt []byte, txId uint16, stream bbsim.Stream) error {
+ indication := &openolt.Indication_OmciInd{
+ OmciInd: &openolt.OmciIndication{
+ IntfId: o.PonPortID,
+ OnuId: o.ID,
+ Pkt: responsePkt,
+ },
}
-
- omciInd.IntfId = o.PonPortID
- omciInd.OnuId = o.ID
- omciInd.Pkt = respPkt
-
- omci := &openolt.Indication_OmciInd{OmciInd: &omciInd}
- if err := stream.Send(&openolt.Indication{Data: omci}); err != nil {
- onuLogger.WithFields(log.Fields{
- "IntfId": o.PonPortID,
- "SerialNumber": o.Sn(),
- "omciPacket": omciInd.Pkt,
- "msg": msg,
- }).Errorf("send omcisim indication failed: %v", err)
- return
+ if err := stream.Send(&openolt.Indication{Data: indication}); err != nil {
+ return fmt.Errorf("failed-to-send-omci-message: %v", err)
}
onuLogger.WithFields(log.Fields{
"IntfId": o.PonPortID,
"SerialNumber": o.Sn(),
- "omciPacket": omciInd.Pkt,
- }).Tracef("Sent OMCI message")
-
- // Test message is special, it requires sending two packets:
- // first packet: TestResponse, says whether test was started successully, handled by omci-sim
- // second packet, TestResult, reports the result of running the self-test
- // TestResult can come some time after a TestResponse
- // TODO: Implement some delay between the TestResponse and the TestResult
- isTest, err := omcilib.IsTestRequest(HexDecode(msg.omciMsg.Pkt))
- if (err == nil) && (isTest) {
- _ = o.sendTestResult(msg, stream)
- }
+ "omciPacket": indication.OmciInd.Pkt,
+ "transCorrId": txId,
+ }).Trace("omci-message-sent")
+ return nil
}
func (o *Onu) storePortNumber(portNo uint32) {
@@ -602,7 +795,7 @@
o.ID = id
}
-func (o *Onu) handleFlowAdd(msg OnuFlowUpdateMessage) {
+func (o *Onu) handleFlowAdd(msg bbsim.OnuFlowUpdateMessage) {
onuLogger.WithFields(log.Fields{
"Cookie": msg.Flow.Cookie,
"DstPort": msg.Flow.Classifier.DstPort,
@@ -667,7 +860,7 @@
}
}
-func (o *Onu) handleFlowRemove(msg OnuFlowUpdateMessage) {
+func (o *Onu) handleFlowRemove(msg bbsim.OnuFlowUpdateMessage) {
onuLogger.WithFields(log.Fields{
"IntfId": o.PonPortID,
"OnuId": o.ID,
@@ -700,19 +893,6 @@
}
}
-// HexDecode converts the hex encoding to binary
-func HexDecode(pkt []byte) []byte {
- p := make([]byte, len(pkt)/2)
- for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
- // Go figure this ;)
- u := (pkt[i] & 15) + (pkt[i]>>6)*9
- l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
- p[j] = u<<4 + l
- }
- onuLogger.Tracef("Omci decoded: %x.", p)
- return p
-}
-
// BBR methods
func sendOmciMsg(pktBytes []byte, intfId uint32, onuId uint32, sn *openolt.SerialNumber, msgType string, client openolt.OpenoltClient) {
@@ -762,24 +942,36 @@
sendOmciMsg(mibReset, o.PonPortID, o.ID, o.SerialNumber, "mibReset", client)
}
-func (o *Onu) handleOmci(msg OmciIndicationMessage, client openolt.OpenoltClient) {
- msgType, packet := omcilib.DecodeOmci(msg.OmciInd.Pkt)
+// handleOmciResponse is used in BBR to generate the OMCI packets the openolt-adapter would send to the device
+func (o *Onu) handleOmciResponse(msg bbsim.OmciIndicationMessage, client openolt.OpenoltClient) {
+
+ // we need to encode the packet in HEX
+ pkt := make([]byte, len(msg.OmciInd.Pkt)*2)
+ hex.Encode(pkt, msg.OmciInd.Pkt)
+ packet, omciMsg, err := omcilib.ParseOpenOltOmciPacket(pkt)
+ if err != nil {
+ log.WithFields(log.Fields{
+ "IntfId": o.PonPortID,
+ "SerialNumber": o.Sn(),
+ "omciPacket": msg.OmciInd.Pkt,
+ }).Error("BBR Cannot parse OMCI packet")
+ }
log.WithFields(log.Fields{
"IntfId": msg.OmciInd.IntfId,
"OnuId": msg.OmciInd.OnuId,
- "OnuSn": common.OnuSnToString(o.SerialNumber),
+ "OnuSn": o.Sn(),
"Pkt": msg.OmciInd.Pkt,
- "msgType": msgType,
+ "msgType": omciMsg.MessageType,
}).Trace("ONU Receives OMCI Msg")
- switch msgType {
+ switch omciMsg.MessageType {
default:
log.WithFields(log.Fields{
"IntfId": msg.OmciInd.IntfId,
"OnuId": msg.OmciInd.OnuId,
- "OnuSn": common.OnuSnToString(o.SerialNumber),
+ "OnuSn": o.Sn(),
"Pkt": msg.OmciInd.Pkt,
- "msgType": msgType,
+ "msgType": omciMsg.MessageType,
}).Fatalf("unexpected frame: %v", packet)
case omci.MibResetResponseType:
mibUpload, _ := omcilib.CreateMibUploadRequest(o.getNextTid(false))
diff --git a/internal/bbsim/devices/onu_flow_test.go b/internal/bbsim/devices/onu_flow_test.go
index 1464ae5..e0ad9fe 100644
--- a/internal/bbsim/devices/onu_flow_test.go
+++ b/internal/bbsim/devices/onu_flow_test.go
@@ -19,6 +19,7 @@
import (
"github.com/google/gopacket/layers"
"github.com/looplab/fsm"
+ "github.com/opencord/bbsim/internal/bbsim/types"
"github.com/opencord/voltha-protos/v4/go/openolt"
"gotest.tools/assert"
"testing"
@@ -54,7 +55,7 @@
FlowId: 64,
Classifier: &openolt.Classifier{},
}
- msg := OnuFlowUpdateMessage{
+ msg := types.OnuFlowUpdateMessage{
OnuID: onu.ID,
PonPortID: onu.PonPortID,
Flow: &flow,
@@ -74,7 +75,7 @@
FlowId: 64,
Classifier: &openolt.Classifier{},
}
- msg := OnuFlowUpdateMessage{
+ msg := types.OnuFlowUpdateMessage{
OnuID: onu.ID,
PonPortID: onu.PonPortID,
Flow: &flow,
@@ -107,7 +108,7 @@
FlowId: 64,
Classifier: &openolt.Classifier{},
}
- msg := OnuFlowUpdateMessage{
+ msg := types.OnuFlowUpdateMessage{
OnuID: onu.ID,
PonPortID: onu.PonPortID,
Flow: &flow,
@@ -147,7 +148,7 @@
PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
}
- msg := OnuFlowUpdateMessage{
+ msg := types.OnuFlowUpdateMessage{
PonPortID: 1,
OnuID: 1,
Flow: &flow,
@@ -194,7 +195,7 @@
PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
}
- msg := OnuFlowUpdateMessage{
+ msg := types.OnuFlowUpdateMessage{
PonPortID: 1,
OnuID: 1,
Flow: &flow,
@@ -235,7 +236,7 @@
PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
}
- msg := OnuFlowUpdateMessage{
+ msg := types.OnuFlowUpdateMessage{
PonPortID: 1,
OnuID: 1,
Flow: &flow,
@@ -279,7 +280,7 @@
PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
}
- msg := OnuFlowUpdateMessage{
+ msg := types.OnuFlowUpdateMessage{
PonPortID: 1,
OnuID: 1,
Flow: &flow,
@@ -323,7 +324,7 @@
PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
}
- msg := OnuFlowUpdateMessage{
+ msg := types.OnuFlowUpdateMessage{
PonPortID: 1,
OnuID: 1,
Flow: &flow,
@@ -367,7 +368,7 @@
PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
}
- msg := OnuFlowUpdateMessage{
+ msg := types.OnuFlowUpdateMessage{
PonPortID: 1,
OnuID: 1,
Flow: &flow,
@@ -409,7 +410,7 @@
PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
}
- msg := OnuFlowUpdateMessage{
+ msg := types.OnuFlowUpdateMessage{
PonPortID: 1,
OnuID: 1,
Flow: &flow,
@@ -457,7 +458,7 @@
PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
}
- msg := OnuFlowUpdateMessage{
+ msg := types.OnuFlowUpdateMessage{
PonPortID: 1,
OnuID: 1,
Flow: &flow,
diff --git a/internal/bbsim/devices/onu_test_helpers.go b/internal/bbsim/devices/onu_test_helpers.go
index 89eb195..ef6e4a2 100644
--- a/internal/bbsim/devices/onu_test_helpers.go
+++ b/internal/bbsim/devices/onu_test_helpers.go
@@ -19,6 +19,7 @@
import (
"context"
"errors"
+ "github.com/opencord/bbsim/internal/bbsim/types"
"github.com/opencord/voltha-protos/v4/go/common"
"github.com/opencord/voltha-protos/v4/go/ext/config"
"time"
@@ -137,7 +138,7 @@
},
}
o.SerialNumber = o.NewSN(0, ponPortId, o.ID)
- o.Channel = make(chan Message, 10)
+ o.Channel = make(chan types.Message, 10)
return &o
}
diff --git a/internal/bbsim/devices/services.go b/internal/bbsim/devices/services.go
index bd4d13c..4391414 100644
--- a/internal/bbsim/devices/services.go
+++ b/internal/bbsim/devices/services.go
@@ -71,9 +71,9 @@
EapolState *fsm.FSM
DHCPState *fsm.FSM
IGMPState *fsm.FSM
- Channel chan Message // drive Service lifecycle
- PacketCh chan OnuPacketMessage // handle packets
- Stream bbsimTypes.Stream // the gRPC stream to communicate with the adapter, created in the initialize transition
+ Channel chan bbsimTypes.Message // drive Service lifecycle
+ PacketCh chan bbsimTypes.OnuPacketMessage // handle packets
+ Stream bbsimTypes.Stream // the gRPC stream to communicate with the adapter, created in the initialize transition
}
func NewService(name string, hwAddress net.HardwareAddr, onu *Onu, cTag int, sTag int,
@@ -117,8 +117,8 @@
service.Stream = stream
- service.PacketCh = make(chan OnuPacketMessage)
- service.Channel = make(chan Message)
+ service.PacketCh = make(chan bbsimTypes.OnuPacketMessage)
+ service.Channel = make(chan bbsimTypes.Message)
go service.HandlePackets()
go service.HandleChannel()
@@ -153,8 +153,8 @@
service.logStateChange("EapolState", e.Src, e.Dst)
},
"before_start_auth": func(e *fsm.Event) {
- msg := Message{
- Type: StartEAPOL,
+ msg := bbsimTypes.Message{
+ Type: bbsimTypes.StartEAPOL,
}
service.Channel <- msg
},
@@ -207,8 +207,8 @@
service.logStateChange("DHCPState", e.Src, e.Dst)
},
"before_start_dhcp": func(e *fsm.Event) {
- msg := Message{
- Type: StartDHCP,
+ msg := bbsimTypes.Message{
+ Type: bbsimTypes.StartDHCP,
}
service.Channel <- msg
},
@@ -255,30 +255,30 @@
},
fsm.Callbacks{
"igmp_join_start": func(e *fsm.Event) {
- igmpInfo, _ := e.Args[0].(IgmpMessage)
- msg := Message{
- Type: IGMPMembershipReportV2,
- Data: IgmpMessage{
+ igmpInfo, _ := e.Args[0].(bbsimTypes.IgmpMessage)
+ msg := bbsimTypes.Message{
+ Type: bbsimTypes.IGMPMembershipReportV2,
+ Data: bbsimTypes.IgmpMessage{
GroupAddress: igmpInfo.GroupAddress,
},
}
service.Channel <- msg
},
"igmp_leave": func(e *fsm.Event) {
- igmpInfo, _ := e.Args[0].(IgmpMessage)
- msg := Message{
- Type: IGMPLeaveGroup,
- Data: IgmpMessage{
+ igmpInfo, _ := e.Args[0].(bbsimTypes.IgmpMessage)
+ msg := bbsimTypes.Message{
+ Type: bbsimTypes.IGMPLeaveGroup,
+ Data: bbsimTypes.IgmpMessage{
GroupAddress: igmpInfo.GroupAddress,
},
}
service.Channel <- msg
},
"igmp_join_startv3": func(e *fsm.Event) {
- igmpInfo, _ := e.Args[0].(IgmpMessage)
- msg := Message{
- Type: IGMPMembershipReportV3,
- Data: IgmpMessage{
+ igmpInfo, _ := e.Args[0].(bbsimTypes.IgmpMessage)
+ msg := bbsimTypes.Message{
+ Type: bbsimTypes.IGMPMembershipReportV3,
+ Data: bbsimTypes.IgmpMessage{
GroupAddress: igmpInfo.GroupAddress,
},
}
@@ -411,7 +411,7 @@
}()
for msg := range s.Channel {
switch msg.Type {
- case StartEAPOL:
+ case bbsimTypes.StartEAPOL:
if err := s.handleEapolStart(s.Stream); err != nil {
serviceLogger.WithFields(log.Fields{
"OnuId": s.Onu.ID,
@@ -422,7 +422,7 @@
}).Error("Error while sending EapolStart packet")
_ = s.EapolState.Event("auth_failed")
}
- case StartDHCP:
+ case bbsimTypes.StartDHCP:
if err := s.handleDHCPStart(s.Stream); err != nil {
serviceLogger.WithFields(log.Fields{
"OnuId": s.Onu.ID,
@@ -434,8 +434,8 @@
_ = s.DHCPState.Event("dhcp_failed")
}
- case IGMPMembershipReportV2:
- igmpInfo, _ := msg.Data.(IgmpMessage)
+ case bbsimTypes.IGMPMembershipReportV2:
+ igmpInfo, _ := msg.Data.(bbsimTypes.IgmpMessage)
serviceLogger.WithFields(log.Fields{
"OnuId": s.Onu.ID,
"IntfId": s.Onu.PonPortID,
@@ -443,8 +443,8 @@
"Name": s.Name,
}).Debug("Received IGMPMembershipReportV2 message on ONU channel")
_ = igmp.SendIGMPMembershipReportV2(s.Onu.PonPortID, s.Onu.ID, s.Onu.Sn(), s.Onu.PortNo, s.GemPort, s.HwAddress, s.CTag, s.UsPonCTagPriority, s.Stream, igmpInfo.GroupAddress)
- case IGMPLeaveGroup:
- igmpInfo, _ := msg.Data.(IgmpMessage)
+ case bbsimTypes.IGMPLeaveGroup:
+ igmpInfo, _ := msg.Data.(bbsimTypes.IgmpMessage)
serviceLogger.WithFields(log.Fields{
"OnuId": s.Onu.ID,
"IntfId": s.Onu.PonPortID,
@@ -452,8 +452,8 @@
"Name": s.Name,
}).Debug("Received IGMPLeaveGroupV2 message on ONU channel")
_ = igmp.SendIGMPLeaveGroupV2(s.Onu.PonPortID, s.Onu.ID, s.Onu.Sn(), s.Onu.PortNo, s.GemPort, s.HwAddress, s.CTag, s.UsPonCTagPriority, s.Stream, igmpInfo.GroupAddress)
- case IGMPMembershipReportV3:
- igmpInfo, _ := msg.Data.(IgmpMessage)
+ case bbsimTypes.IGMPMembershipReportV3:
+ igmpInfo, _ := msg.Data.(bbsimTypes.IgmpMessage)
serviceLogger.WithFields(log.Fields{
"OnuId": s.Onu.ID,
"IntfId": s.Onu.PonPortID,
diff --git a/internal/bbsim/responders/eapol/eapol.go b/internal/bbsim/responders/eapol/eapol.go
index 0860935..688728c 100644
--- a/internal/bbsim/responders/eapol/eapol.go
+++ b/internal/bbsim/responders/eapol/eapol.go
@@ -26,7 +26,6 @@
"github.com/google/gopacket/layers"
"github.com/looplab/fsm"
bbsim "github.com/opencord/bbsim/internal/bbsim/types"
- omci "github.com/opencord/omci-sim"
"github.com/opencord/voltha-protos/v4/go/openolt"
log "github.com/sirupsen/logrus"
)
@@ -36,7 +35,6 @@
})
var eapolVersion uint8 = 1
-var GetGemPortId = omci.GetGemPortId
func sendEapolPktIn(msg bbsim.ByteMsg, portNo uint32, gemid uint32, stream bbsim.Stream) error {
// FIXME unify sendDHCPPktIn and sendEapolPktIn methods
diff --git a/internal/bbsim/responders/eapol/eapol_test.go b/internal/bbsim/responders/eapol/eapol_test.go
index 248fd3d..69f941f 100644
--- a/internal/bbsim/responders/eapol/eapol_test.go
+++ b/internal/bbsim/responders/eapol/eapol_test.go
@@ -94,14 +94,6 @@
eapolStateMachine.SetState("auth_started")
- // Save current function and restore at the end:
- old := GetGemPortId
- defer func() { GetGemPortId = old }()
-
- GetGemPortId = func(oltId int, intfId uint32, onuId uint32) (uint16, error) {
- return 1, nil
- }
-
stream := &mockStream{
Calls: make(map[int]*openolt.PacketIndication),
fail: true,
diff --git a/internal/bbsim/devices/messageTypes.go b/internal/bbsim/types/messageTypes.go
similarity index 89%
rename from internal/bbsim/devices/messageTypes.go
rename to internal/bbsim/types/messageTypes.go
index 144e1b9..3afe7fb 100644
--- a/internal/bbsim/devices/messageTypes.go
+++ b/internal/bbsim/types/messageTypes.go
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package devices
+package types
import (
"github.com/google/gopacket"
@@ -50,6 +50,7 @@
AlarmIndication MessageType = 16 // message data is an openolt.AlarmIndication
IGMPMembershipReportV3 MessageType = 17 // Version 3 Membership Report
+ UniStatusAlarm MessageType = 19
)
func (m MessageType) String() string {
@@ -72,6 +73,7 @@
"IGMPLeaveGroup",
"IGMPMembershipReportV3",
"FlowRemoved",
+ "UniStatusAlarm",
}
return names[m]
}
@@ -97,7 +99,6 @@
type OnuDiscIndicationMessage struct {
OperState OperState
- Onu *Onu
}
type OnuIndicationMessage struct {
@@ -107,12 +108,23 @@
OnuSN *openolt.SerialNumber
}
+// these are OMCI messages going from VOLTHA to the OLT
+// used by BBSim
type OmciMessage struct {
OnuSN *openolt.SerialNumber
OnuID uint32
- omciMsg *openolt.OmciMsg
+ OmciMsg *openolt.OmciMsg
}
+type UniStatusAlarmMessage struct {
+ OnuSN *openolt.SerialNumber
+ OnuID uint32
+ AdminState uint8
+ EntityID uint16
+}
+
+// these are OMCI messages going from the OLT to VOLTHA
+// these messages are received by BBR
type OmciIndicationMessage struct {
OnuSN *openolt.SerialNumber
OnuID uint32