initial add
deleting bin/cert
adding license info

tweaking packages to match go standard conventions

updating to match tweaked package names

Change-Id: I78b395a778c0ceb649e2aa4491c81fd3dc28d0c0
diff --git a/api/abstract_olt_api.proto b/api/abstract_olt_api.proto
new file mode 100644
index 0000000..2dfeff0
--- /dev/null
+++ b/api/abstract_olt_api.proto
@@ -0,0 +1,106 @@
+//Copyright 2017 the original author or authors.
+//
+//  Licensed under the Apache License, Version 2.0 (the "License");
+//  you may not use this file except in compliance with the License.
+//  You may obtain a copy of the License at
+
+//       http://www.apache.org/licenses/LICENSE-2.0
+
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+
+syntax = "proto3";
+package api;
+import "google/api/annotations.proto";
+
+message AddChassisMessage{
+   string CLLI =1;
+   string VCoreIP =2;
+   int32 VCorePort=3;
+}
+message Error {
+   int32 ErrorNum = 1;
+   string ErrorMessage=2;
+   int32 Serverity=3;
+}
+message AddChassisReturn{
+   string DeviceID = 1;
+   Error error = 2;
+}
+message AddOLTChassisMessage{
+   string CLLI=1;
+   string SlotIP=2;
+   fixed32 SlotPort=3;
+   string Hostname=4;
+   fixed32 NumPorts = 5;
+   bool Activate = 6;
+   enum OltDriver {
+      openoltDriver = 0;
+      asfvolt16Driver=1;
+      adtranDriver=2;
+      tibitsDriver=3;
+   }
+   OltDriver Driver=7;
+   enum OltType{
+      edgecore=0;
+      adtran=1;
+      tibit=2;
+   }
+   OltType Type=8;
+
+}
+message AddOLTChassisReturn {
+   string DeviceID =1;
+   string ChassisDeviceID =2;
+   Error error = 3;
+}
+message ActivateSlotMessage{
+   string SlotDeviceID = 1;
+}
+message ActivateSlotReturn{
+   bool Success = 1;
+   Error error = 2;
+}
+message AddOntMessage{
+   string ChassisDeviceID=1;
+   string SlotDeviceID=2;
+   int32 PortNumber=3;
+   int32 OntNumber=4;
+}
+message AddOntReturn{
+   bool Success=1;
+   Error error = 2;
+}
+
+service AddChassis{
+   rpc CreateChassis(AddChassisMessage) returns (AddChassisReturn) {
+      option(google.api.http) = {
+         post: "/1/CreateAbstractChassis"
+	 body:"*"
+      };
+   }
+}
+
+service AddOLTChassis {
+   rpc CreateOLTChassis(AddOLTChassisMessage) returns (AddOLTChassisReturn) {
+      option(google.api.http) = {
+         post: "/1/CreateOLTChassis"
+	 body:"*"
+      };
+   }
+}
+service ActivateSlot{
+   rpc EnableSlot(ActivateSlotMessage) returns (ActivateSlotReturn){
+      option(google.api.http) = {
+         post: "/1/EnableSlot"
+	 body:"*"
+      };
+   }
+}
+service ActivateOnt {
+   rpc ProvisionOnt(AddOntMessage) returns (AddOntReturn) {}
+}
+
diff --git a/api/handler.go b/api/handler.go
new file mode 100644
index 0000000..ec7ce86
--- /dev/null
+++ b/api/handler.go
@@ -0,0 +1,111 @@
+/*
+ Copyright 2017 the original author or authors.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package api
+
+import (
+	"fmt"
+	"log"
+	"net"
+	"strings"
+
+	"gerrit.opencord.org/abstract-olt/internal/pkg/settings"
+	"gerrit.opencord.org/abstract-olt/models"
+	"gerrit.opencord.org/abstract-olt/models/abstract"
+	"gerrit.opencord.org/abstract-olt/models/physical"
+	context "golang.org/x/net/context"
+)
+
+/*
+Server instance of the grpc server
+*/
+type Server struct {
+}
+
+/*
+CreateChassis - allocates a new Chassis struct and stores it in chassisMap
+*/
+func (s *Server) CreateChassis(ctx context.Context, in *AddChassisMessage) (*AddChassisReturn, error) {
+	phyChassisMap := models.GetPhyChassisMap()
+	absChassisMap := models.GetAbstractChassisMap()
+	clli := in.GetCLLI()
+
+	chassis := (*phyChassisMap)[clli]
+	if chassis != nil {
+		return &AddChassisReturn{DeviceID: chassis.CLLI}, nil
+	}
+	abstractChassis := abstract.GenerateChassis(clli)
+	phyChassis := physical.Chassis{CLLI: clli}
+	if settings.GetDebug() {
+		output := fmt.Sprintf("%v", abstractChassis)
+		formatted := strings.Replace(output, "{", "\n{", -1)
+		log.Printf("new chassis %s\n", formatted)
+	}
+	(*phyChassisMap)[clli] = &phyChassis
+	(*absChassisMap)[clli] = abstractChassis
+	return &AddChassisReturn{DeviceID: clli}, nil
+}
+
+/*
+AddOLTChassis adds an OLT chassis/line card to the Physical chassis
+*/
+func (s *Server) CreateOLTChassis(ctx context.Context, in *AddOLTChassisMessage) (*AddOLTChassisReturn, error) {
+	fmt.Printf(" CreateOLTChassis %v \n", *in)
+	phyChassisMap := models.GetPhyChassisMap()
+	clli := in.GetCLLI()
+	chassis := (*phyChassisMap)[clli]
+	if chassis == nil {
+	}
+	oltType := in.GetType()
+	address := net.TCPAddr{IP: net.ParseIP(in.GetSlotIP()), Port: int(in.GetSlotPort())}
+	sOlt := physical.SimpleOLT{CLLI: clli, Hostname: in.GetHostname(), Address: address}
+
+	var olt physical.OLT
+	switch oltType {
+	case AddOLTChassisMessage_edgecore:
+		olt = physical.CreateEdgecore(&sOlt)
+	case AddOLTChassisMessage_adtran:
+	case AddOLTChassisMessage_tibit:
+	}
+
+	err := AddCard(chassis, olt)
+	if err != nil {
+		//TODO do something
+	}
+
+	return &AddOLTChassisReturn{DeviceID: in.GetHostname(), ChassisDeviceID: clli}, nil
+
+}
+
+/*
+AddCard Adds an OLT card to an existing physical chassis, allocating ports
+in the physical card to those in the abstract model
+*/
+func AddCard(physChassis *physical.Chassis, olt physical.OLT) error {
+	physChassis.Linecards = append(physChassis.Linecards, olt)
+
+	ports := olt.GetPorts()
+	absChassis := (*models.GetAbstractChassisMap())[physChassis.CLLI]
+
+	for i := 0; i < len(ports); i++ {
+		absPort, _ := absChassis.NextPort()
+		absPort.PhysPort = &ports[i]
+		//AssignTraits(&ports[i], absPort)
+	}
+
+	//should probably worry about error at some point
+	return nil
+}