seba-328 - better error handling

Change-Id: I42f28ea4b003ce4619516852d9ce74db3916179a
diff --git a/api/handler.go b/api/handler.go
index 3b1754f..4e1ef61 100644
--- a/api/handler.go
+++ b/api/handler.go
@@ -110,9 +110,10 @@
 func (s *Server) CreateOLTChassis(ctx context.Context, in *AddOLTChassisMessage) (*AddOLTChassisReturn, error) {
 	clli := in.GetCLLI()
 	oltType := in.GetType().String()
+	driver := in.GetDriver().String()
 	address := net.TCPAddr{IP: net.ParseIP(in.GetSlotIP()), Port: int(in.GetSlotPort())}
 	hostname := in.GetHostname()
-	clli, err := impl.CreateOLTChassis(clli, oltType, address, hostname)
+	clli, err := impl.CreateOLTChassis(clli, oltType, driver, address, hostname)
 	return &AddOLTChassisReturn{DeviceID: hostname, ChassisDeviceID: clli}, err
 }
 
diff --git a/internal/pkg/impl/olt.go b/internal/pkg/impl/olt.go
index b878a9b..28c8820 100644
--- a/internal/pkg/impl/olt.go
+++ b/internal/pkg/impl/olt.go
@@ -28,7 +28,7 @@
 /*
 CreateOLTChassis adds an OLT chassis/line card to the Physical chassis
 */
-func CreateOLTChassis(clli string, oltType string, address net.TCPAddr, hostname string) (string, error) {
+func CreateOLTChassis(clli string, oltType string, driver string, address net.TCPAddr, hostname string) (string, error) {
 	myChan := getSyncChannel()
 	<-myChan
 	defer done(myChan, true)
@@ -39,21 +39,24 @@
 		return "", errors.New(errString)
 	}
 	physicalChassis := &chassisHolder.PhysicalChassis
-	sOlt := physical.SimpleOLT{CLLI: clli, Hostname: hostname, Address: address, Parent: physicalChassis}
+	sOlt := physical.SimpleOLT{CLLI: clli, Hostname: hostname, Driver: driver, Address: address, Parent: physicalChassis}
 	switch oltType {
 	case "edgecore":
 		sOlt.CreateEdgecore()
 	case "adtran":
 	case "tibit":
 	}
-	physicalChassis.AddOLTChassis(sOlt)
 	ports := sOlt.GetPorts()
 	for i := 0; i < len(ports); i++ {
-		absPort, _ := chassisHolder.AbstractChassis.NextPort()
-
+		absPort, err := chassisHolder.AbstractChassis.NextPort()
+		if err != nil {
+			fmt.Println(err)
+			return "", err
+		}
 		absPort.PhysPort = &ports[i]
 		//AssignTraits(&ports[i], absPort)
 	}
+	physicalChassis.AddOLTChassis(sOlt)
 	isDirty = true
 	return clli, nil
 
diff --git a/models/abstract/chassis.go b/models/abstract/chassis.go
index a86822d..2b3231b 100644
--- a/models/abstract/chassis.go
+++ b/models/abstract/chassis.go
@@ -18,6 +18,7 @@
 
 import (
 	"errors"
+	"fmt"
 )
 
 const MAX_SLOTS int = 16
@@ -63,15 +64,52 @@
 	return nextPort, nil
 }
 func (chassis *Chassis) ActivateONTFull(slotNumber int, portNumber int, ontNumber int, serialNumber string, cTag uint32, sTag uint32, nasPortID string, circuitID string) error {
+	if slotNumber > len(chassis.Slots) {
+		errorMsg := fmt.Sprintf("Invalid slot Number %d ", slotNumber)
+		return errors.New(errorMsg)
+	}
+	if portNumber > 16 {
+		errorMsg := fmt.Sprintf("Invalid port Number %d ", portNumber)
+		return errors.New(errorMsg)
+	}
+	if ontNumber > 64 {
+		errorMsg := fmt.Sprintf("Invalid ont Number %d ", ontNumber)
+		return errors.New(errorMsg)
+	}
+
 	err := chassis.Slots[slotNumber-1].Ports[portNumber-1].provisionOntFull(ontNumber, serialNumber, cTag, sTag, nasPortID, circuitID)
 	return err
 }
 
 func (chassis *Chassis) ActivateONT(slotNumber int, portNumber int, ontNumber int, serialNumber string) error {
+	if slotNumber > len(chassis.Slots) {
+		errorMsg := fmt.Sprintf("Invalid slot Number %d ", slotNumber)
+		return errors.New(errorMsg)
+	}
+	if portNumber > 16 {
+		errorMsg := fmt.Sprintf("Invalid port Number %d ", portNumber)
+		return errors.New(errorMsg)
+	}
+	if ontNumber > 64 {
+		errorMsg := fmt.Sprintf("Invalid ont Number %d ", ontNumber)
+		return errors.New(errorMsg)
+	}
 	err := chassis.Slots[slotNumber-1].Ports[portNumber-1].provisionOnt(ontNumber, serialNumber)
 	return err
 }
 func (chassis *Chassis) DeleteONT(slotNumber int, portNumber int, ontNumber int, serialNumber string) error {
+	if slotNumber > len(chassis.Slots) {
+		errorMsg := fmt.Sprintf("Invalid slot Number %d ", slotNumber)
+		return errors.New(errorMsg)
+	}
+	if portNumber > 16 {
+		errorMsg := fmt.Sprintf("Invalid port Number %d ", portNumber)
+		return errors.New(errorMsg)
+	}
+	if ontNumber > 64 {
+		errorMsg := fmt.Sprintf("Invalid ont Number %d ", ontNumber)
+		return errors.New(errorMsg)
+	}
 	err := chassis.Slots[slotNumber-1].Ports[portNumber-1].deleteOnt(ontNumber, serialNumber)
 	return err
 }
diff --git a/models/physical/chassis.go b/models/physical/chassis.go
index 59c87b7..943c830 100644
--- a/models/physical/chassis.go
+++ b/models/physical/chassis.go
@@ -70,7 +70,7 @@
 func (chassis *Chassis) SendOltTosca(olt SimpleOLT) {
 	ipString := olt.GetAddress().IP.String()
 	webServerPort := olt.GetAddress().Port
-	oltStruct := tosca.NewOltProvision(chassis.CLLI, olt.GetHostname(), "openolt", ipString, webServerPort)
+	oltStruct := tosca.NewOltProvision(chassis.CLLI, olt.GetHostname(), olt.Driver, ipString, webServerPort)
 	yaml, _ := oltStruct.ToYaml()
 	if settings.GetDummy() {
 		log.Printf("yaml:%s\n", yaml)
diff --git a/models/physical/olt.go b/models/physical/olt.go
index c800ad5..321c895 100644
--- a/models/physical/olt.go
+++ b/models/physical/olt.go
@@ -42,6 +42,7 @@
 	CLLI           string
 	Hostname       string
 	Address        net.TCPAddr
+	Driver         string
 	Number         int
 	Ports          []PONPort
 	Active         bool