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/models/abstract/ChassisUtils.go b/models/abstract/ChassisUtils.go
new file mode 100644
index 0000000..4c41698
--- /dev/null
+++ b/models/abstract/ChassisUtils.go
@@ -0,0 +1,105 @@
+/*
+   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 abstract
+
+import "errors"
+
+/*
+GenerateChassis - constructs a new AbstractOLT Chassis
+*/
+func GenerateChassis(CLLI string) *Chassis {
+	chassis := Chassis{CLLI: CLLI}
+
+	var slots [16]Slot
+	for i := 0; i < 16; i++ {
+		slots[i] = generateSlot(i, &chassis)
+	}
+
+	chassis.Slots = slots
+	return &chassis
+}
+
+func generateSlot(n int, c *Chassis) Slot {
+	slot := Slot{Number: n, Parent: c}
+
+	var ports [16]Port
+	for i := 0; i < 16; i++ {
+		ports[i] = generatePort(i, &slot)
+	}
+
+	slot.Ports = ports
+	return slot
+}
+func generatePort(n int, s *Slot) Port {
+	port := Port{Number: n, Parent: s}
+
+	var onts [64]Ont
+	for i := 0; i < 64; i++ {
+		/* adding one because the system that provisions is 1 based on everything not 0 based*/
+		onts[i] = Ont{Number: i, Svlan: calculateSvlan(s.Number+1, n+1, i+1),
+			Cvlan: calculateCvlan(s.Number+1, n+1, i+1), Parent: &port}
+	}
+
+	port.Onts = onts
+	return port
+}
+
+func calculateCvlan(slot int, port int, ont int) int {
+	ontPortOffset := 120 // Max(ONT_SLOT) * Max(ONT_PORT) = 10 * 12 = 120
+	ontSlotOffset := 12  //= Max(ONT_PORT) = 12
+	vlanOffset := 1      //(VID 1 is reserved)
+
+	cVid := ((ont-1)%32)*ontPortOffset +
+		(slot-1)*ontSlotOffset + port + vlanOffset
+
+	return cVid
+}
+
+func calculateSvlan(slot int, port int, ont int) int {
+	ltSlotOffset := 16
+	vlanGap := 288  // Max(LT_SLOT) * Max(ltSlotOffset) = 18 * 16 = 288
+	vlanOffset := 1 //(VID 1 is reserved)
+
+	sVid := ((slot-1)*ltSlotOffset + port) + ((ont-1)/32)*vlanGap + vlanOffset
+
+	return sVid
+}
+
+/*
+NextPort pulls the first unMapped port in the abstract chassis so the next physical port can be mapped to it
+*/
+func (chassis *Chassis) NextPort() (*Port, error) {
+	info := &chassis.AllocInfo
+
+	if info.outOfPorts {
+		return nil, errors.New("Abstract chassis out of ports")
+	}
+
+	nextPort := &chassis.Slots[info.slot].Ports[info.port]
+
+	info.port++
+	if info.port == MAX_PORTS {
+		info.port = 0
+		info.slot++
+		if info.slot == MAX_SLOTS {
+			info.slot = 0
+			info.outOfPorts = true
+		}
+	}
+
+	return nextPort, nil
+}
diff --git a/models/abstract/chassis.go b/models/abstract/chassis.go
new file mode 100644
index 0000000..52de90d
--- /dev/null
+++ b/models/abstract/chassis.go
@@ -0,0 +1,36 @@
+/*
+   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 abstract
+
+const MAX_SLOTS int = 16
+const MAX_PORTS int = 16
+
+/*
+Chassis is a model that takes up to 16 discreet OLT chassis as if it is a 16 slot OLT chassis
+*/
+type Chassis struct {
+	CLLI      string
+	Slots     [16]Slot
+	AllocInfo PortAllocationInfo
+}
+
+type PortAllocationInfo struct {
+	// Current info on next port to be allocated
+	slot       int
+	port       int
+	outOfPorts bool
+}
diff --git a/models/abstract/ont.go b/models/abstract/ont.go
new file mode 100644
index 0000000..bfd6d60
--- /dev/null
+++ b/models/abstract/ont.go
@@ -0,0 +1,27 @@
+/*
+   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 abstract
+
+/*
+Ont represents a single ont/onu connect to a splitter on a Port
+*/
+type Ont struct {
+	Number int
+	Svlan  int
+	Cvlan  int
+	Parent *Port `json:"-"`
+}
diff --git a/models/abstract/port.go b/models/abstract/port.go
new file mode 100644
index 0000000..c23249a
--- /dev/null
+++ b/models/abstract/port.go
@@ -0,0 +1,30 @@
+/*
+   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 abstract
+
+import "gerrit.opencord.org/abstract-olt/models/physical"
+
+/*
+Port represents a single PON port on the OLT chassis
+*/
+type Port struct {
+	Number int
+	// DeviceID string
+	Onts     [64]Ont
+	PhysPort *physical.PONPort
+	Parent   *Slot `json:"-"`
+}
diff --git a/models/abstract/slot.go b/models/abstract/slot.go
new file mode 100644
index 0000000..343542e
--- /dev/null
+++ b/models/abstract/slot.go
@@ -0,0 +1,30 @@
+/*
+   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 abstract
+
+/*
+Slot models a collection of PON ports (likely a single chassis) as if it is a
+line card within a chassis
+*/
+type Slot struct {
+	// DeviceID string
+	// Hostname string
+	// Address  net.TCPAddr
+	Number int
+	Ports  [16]Port
+	Parent *Chassis `json:"-"`
+}
diff --git a/models/chassisMap.go b/models/chassisMap.go
new file mode 100644
index 0000000..30ae8e3
--- /dev/null
+++ b/models/chassisMap.go
@@ -0,0 +1,53 @@
+/*
+   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 models
+
+import (
+	"fmt"
+
+	"gerrit.opencord.org/abstract-olt/models/abstract"
+	"gerrit.opencord.org/abstract-olt/models/physical"
+)
+
+var chassisMap map[string]*physical.Chassis
+var abstractChassisMap map[string]*abstract.Chassis
+
+/*
+GetPhyChassisMap return the chassis map singleton
+*/
+func GetPhyChassisMap() *map[string]*physical.Chassis {
+	if chassisMap == nil {
+		fmt.Println("chassisMap was nil")
+		chassisMap = make(map[string]*physical.Chassis)
+
+	}
+	fmt.Printf("chassis map %v\n", chassisMap)
+	return &chassisMap
+}
+
+/*
+GetAbstractChassisMap return the chassis map singleton
+*/
+func GetAbstractChassisMap() *map[string]*abstract.Chassis {
+	if abstractChassisMap == nil {
+		fmt.Println("chassisMap was nil")
+		abstractChassisMap = make(map[string]*abstract.Chassis)
+
+	}
+	fmt.Printf("chassis map %v\n", chassisMap)
+	return &abstractChassisMap
+}
diff --git a/models/physical/chassis.go b/models/physical/chassis.go
new file mode 100644
index 0000000..339a610
--- /dev/null
+++ b/models/physical/chassis.go
@@ -0,0 +1,29 @@
+/*
+   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 physical
+
+import "net"
+
+/*
+Chassis is a model that takes up to 16 discreet OLT chassis as if it is a 16 slot OLT chassis
+*/
+type Chassis struct {
+	CLLI         string
+	VCoreAddress net.TCPAddr
+	Dataswitch   DataSwitch
+	Linecards    []OLT
+}
diff --git a/models/physical/dataswitch.go b/models/physical/dataswitch.go
new file mode 100644
index 0000000..9146e7f
--- /dev/null
+++ b/models/physical/dataswitch.go
@@ -0,0 +1,30 @@
+/*
+   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 physical
+
+import "net"
+
+type DataSwitch struct {
+	Ports        [32]EthPort
+	Driver       string
+	Ipv4Loopback net.TCPAddr
+	Ipv4NodeSid  int
+	isEdgeRouter bool
+	Name         string
+	OfId         string
+	RouterMac    string
+}
diff --git a/models/physical/edgecore.go b/models/physical/edgecore.go
new file mode 100644
index 0000000..196d44e
--- /dev/null
+++ b/models/physical/edgecore.go
@@ -0,0 +1,34 @@
+/*
+   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 physical
+
+/*
+Edgecore Implements the Edgecore linecard as an OLT
+*/
+type Edgecore struct {
+	SimpleOLT
+}
+
+/*
+CreateEdgecore takes simple olt struct and generates Edgecore OLT
+*/
+func CreateEdgecore(olt *SimpleOLT) *Edgecore {
+	var newPorts [16]PONPort
+	edge := Edgecore{SimpleOLT: *olt}
+	edge.Ports = newPorts[:]
+	return &edge
+}
diff --git a/models/physical/ethdevice.go b/models/physical/ethdevice.go
new file mode 100644
index 0000000..979edb2
--- /dev/null
+++ b/models/physical/ethdevice.go
@@ -0,0 +1,27 @@
+/*
+   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 physical
+
+/*
+EthDevice represents a device with an ethernet port
+*/
+type EthDevice interface {
+}
+
+type EthPort struct {
+	Connected *EthDevice
+}
diff --git a/models/physical/olt.go b/models/physical/olt.go
new file mode 100644
index 0000000..3c2094d
--- /dev/null
+++ b/models/physical/olt.go
@@ -0,0 +1,74 @@
+/*
+   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 physical
+
+import "net"
+
+/*
+Represents an arbitrary OLT linecard
+*/
+type OLT interface {
+	GetCLLI() string
+	GetHostname() string
+	GetAddress() net.TCPAddr
+	GetNumber() int
+	GetPorts() []PONPort
+	GetParent() *Chassis
+	GetDataSwitchPort() int
+}
+
+/*
+A basic representation of an OLT which fulfills the above interface,
+and can be used in other OLT implementations
+*/
+type SimpleOLT struct {
+	CLLI           string
+	Hostname       string
+	Address        net.TCPAddr
+	Number         int
+	Ports          []PONPort
+	Parent         *Chassis `json:"-"`
+	DataSwitchPort int
+}
+
+func (s *SimpleOLT) GetCLLI() string {
+	return s.CLLI
+}
+
+func (s *SimpleOLT) GetHostname() string {
+	return s.Hostname
+}
+
+func (s *SimpleOLT) GetAddress() net.TCPAddr {
+	return s.Address
+}
+
+func (s *SimpleOLT) GetNumber() int {
+	return s.Number
+}
+
+func (s *SimpleOLT) GetPorts() []PONPort {
+	return s.Ports
+}
+
+func (s *SimpleOLT) GetParent() *Chassis {
+	return s.Parent
+}
+
+func (s *SimpleOLT) GetDataSwitchPort() int {
+	return s.DataSwitchPort
+}
diff --git a/models/physical/ont.go b/models/physical/ont.go
new file mode 100644
index 0000000..4bd47ac
--- /dev/null
+++ b/models/physical/ont.go
@@ -0,0 +1,27 @@
+/*
+   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 physical
+
+/*
+Ont represents a single ont/onu connect to a splitter on a Port
+*/
+type Ont struct {
+	Number int
+	Svlan  int
+	Cvlan  int
+	Parent *PONPort `json:"-"`
+}
diff --git a/models/physical/ponport.go b/models/physical/ponport.go
new file mode 100644
index 0000000..99c282a
--- /dev/null
+++ b/models/physical/ponport.go
@@ -0,0 +1,27 @@
+/*
+   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 physical
+
+/*
+Port represents a single PON port on the OLT chassis
+*/
+type PONPort struct {
+	Number   int
+	DeviceID string
+	Onts     [64]Ont
+	Parent   *Edgecore `json:"-"`
+}