[VOL-2778] Introducing Service definition in order to support the TT workflow

Change-Id: Ib171502e8940b5d0b219620a4503f7095d376d7a
diff --git a/internal/bbr/devices/olt.go b/internal/bbr/devices/olt.go
index 01aa411..35b5697 100644
--- a/internal/bbr/devices/olt.go
+++ b/internal/bbr/devices/olt.go
@@ -18,7 +18,7 @@
 
 import (
 	"context"
-	"errors"
+	"encoding/hex"
 	"fmt"
 	"io"
 	"reflect"
@@ -57,7 +57,7 @@
 			if err := onu.InternalState.Event("initialize"); err != nil {
 				log.Fatalf("Error initializing ONU: %v", err)
 			}
-			log.Debugf("Created ONU: %s (%d:%d)", onu.Sn(), onu.STag, onu.CTag)
+			log.Debugf("Created ONU: %s", onu.Sn())
 		}
 	}
 
@@ -91,19 +91,6 @@
 	return client.GetDeviceInfo(ctx, new(openolt.Empty))
 }
 
-func (o *OltMock) getOnuByTags(sTag int, cTag int) (*devices.Onu, error) {
-
-	for _, pon := range o.Olt.Pons {
-		for _, onu := range pon.Onus {
-			if onu.STag == sTag && onu.CTag == cTag {
-				return onu, nil
-			}
-		}
-	}
-
-	return nil, errors.New("cant-find-onu-by-c-s-tags")
-}
-
 func (o *OltMock) readIndications(client openolt.OpenoltClient) {
 	defer func() {
 		log.Info("OLT readIndications done")
@@ -320,28 +307,36 @@
 
 	if pktIndication.IntfType == "nni" {
 		// This is an packet that is arriving from the NNI and needs to be sent to an ONU
-		// in this case we need to fin the ONU from the C/S tags
-		// TODO: handle errors in the untagging process
-		sTag, _ := packetHandlers.GetVlanTag(pkt)
-		singleTagPkt, _ := packetHandlers.PopSingleTag(pkt)
-		cTag, _ := packetHandlers.GetVlanTag(singleTagPkt)
 
-		onu, err := o.getOnuByTags(int(sTag), int(cTag))
+		onuMac, err := packetHandlers.GetDstMacAddressFromPacket(pkt)
 
 		if err != nil {
 			log.WithFields(log.Fields{
-				"sTag": sTag,
-				"cTag": cTag,
-			}).Fatalf("Can't find ONU from c/s tags")
+				"IntfType": "nni",
+				"Pkt":      hex.EncodeToString(pkt.Data()),
+			}).Fatal("Can't find Dst MacAddress in packet")
 		}
 
+		s, err := o.Olt.FindServiceByMacAddress(onuMac)
+		if err != nil {
+			log.WithFields(log.Fields{
+				"IntfType":   "nni",
+				"Pkt":        hex.EncodeToString(pkt.Data()),
+				"MacAddress": onuMac.String(),
+			}).Fatal("Can't find ONU with MacAddress")
+		}
+
+		service := s.(*devices.Service)
+		onu := service.Onu
+
 		msg := devices.Message{
 			Type: devices.OnuPacketIn,
 			Data: devices.OnuPacketMessage{
-				IntfId: pktIndication.IntfId,
-				OnuId:  onu.ID,
-				Packet: pkt,
-				Type:   pktType,
+				IntfId:    pktIndication.IntfId,
+				OnuId:     onu.ID,
+				Packet:    pkt,
+				Type:      pktType,
+				GemPortId: pktIndication.GemportId,
 			},
 		}
 		// NOTE we send it on the ONU channel so that is handled as all the others packets in a separate thread
diff --git a/internal/bbr/devices/validate.go b/internal/bbr/devices/validate.go
index e6d9594..29fcba4 100644
--- a/internal/bbr/devices/validate.go
+++ b/internal/bbr/devices/validate.go
@@ -35,7 +35,7 @@
 	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 	defer cancel()
 
-	onus, err := client.GetONUs(ctx, &bbsim.Empty{})
+	services, err := client.GetServices(ctx, &bbsim.Empty{})
 
 	if err != nil {
 		log.WithFields(log.Fields{
@@ -43,25 +43,29 @@
 		}).Fatalf("Can't reach BBSim API")
 	}
 
-	expectedState := "dhcp_ack_received"
+	expectedEapolState := "eap_response_success_received"
+	expectedDhcpState := "dhcp_ack_received"
 
 	res := true
-	for _, onu := range onus.Items {
-		if onu.InternalState != expectedState {
+	for _, service := range services.Items {
+		if service.DhcpState != expectedDhcpState || service.EapolState != expectedEapolState {
 			res = false
 			log.WithFields(log.Fields{
-				"OnuSN":         onu.SerialNumber,
-				"OnuId":         onu.ID,
-				"InternalState": onu.InternalState,
-				"ExpectedSatte": expectedState,
-			}).Error("Not matching expected state")
+				"OnuSN":              service.OnuSn,
+				"ServiceName":        service.Name,
+				"DhcpState":          service.DhcpState,
+				"EapolState":         service.EapolState,
+				"ExpectedDhcpState":  expectedDhcpState,
+				"ExpectedEapolState": expectedEapolState,
+			}).Fatal("Not matching expected state")
 		}
 	}
 
 	if res {
+		// NOTE that in BBR we expect to have a single service but this is not always the case
 		log.WithFields(log.Fields{
-			"ExpectedState": expectedState,
-		}).Infof("%d ONUs matching expected state", len(onus.Items))
+			"ExpectedState": expectedDhcpState,
+		}).Infof("%d ONUs matching expected state", len(services.Items))
 	}
 
 	olt.conn.Close()