SEBA-122
bin/client is now cmdline app, tosca is sent to xos
Change-Id: I7bbf59569b5c96062aa1c7681708a4cf39532ae2
diff --git a/models/tosca/addOlt.go b/models/tosca/addOlt.go
new file mode 100644
index 0000000..0005800
--- /dev/null
+++ b/models/tosca/addOlt.go
@@ -0,0 +1,124 @@
+/*
+ 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 tosca
+
+import (
+ "log"
+
+ yaml "gopkg.in/yaml.v2"
+)
+
+var templateData = `
+tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+ - custom_types/oltdevice.yaml
+ - custom_types/onudevice.yaml
+ - custom_types/ponport.yaml
+ - custom_types/voltservice.yaml
+description: Create a simulated OLT Device in VOLTHA
+topology_template:
+ node_templates:
+ service#volt:
+ type: tosca.nodes.VOLTService
+ properties:
+ name: volt
+ must-exist: true
+ olt_device:
+ type: tosca.nodes.OLTDevice
+ properties:
+ name: test
+ type: test
+ host: test
+ port: 32
+ outer_tpid: "0x8100"
+ uplink: "65536"
+ nas_id:
+ requirements:
+ - volt_service:
+ node: service#volt
+ relationship: tosca.relationships.BelongsToOne
+`
+
+type OltProvsion struct {
+ ToscaDefinitionsVersion string `yaml:"tosca_definitions_version"`
+ Imports []string `yaml:"imports"`
+ Description string `yaml:"description"`
+ TopologyTemplate struct {
+ NodeTemplates struct {
+ ServiceVolt struct {
+ Type string `yaml:"type"`
+ Properties struct {
+ Name string `yaml:"name"`
+ MustExist bool `yaml:"must-exist"`
+ } `yaml:"properties"`
+ } `yaml:"service#volt"`
+ OltDevice struct {
+ DeviceType string `yaml:"type"`
+ Properties struct {
+ Name string `yaml:"name"`
+ Type string `yaml:"device_type"`
+ Host string `yaml:"host"`
+ Port int `yaml:"port"`
+ OuterTpid string `yaml:"outer_tpid"`
+ Uplink string `yaml:"uplink"`
+ NasID string `yaml:"nas_id"`
+ } `yaml:"properties"`
+ Requirements []struct {
+ VoltService struct {
+ Node string `yaml:"node"`
+ Relationship string `yaml:"relationship"`
+ } `yaml:"volt_service"`
+ } `yaml:"requirements"`
+ } `yaml:"olt_device"`
+ } `yaml:"node_templates"`
+ } `yaml:"topology_template"`
+}
+
+/*var templateData = `
+tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+ - custom_types/oltdevice.yaml
+ - custom_types/onudevice.yaml
+ - custom_types/ponport.yaml
+ - custom_types/voltservice.yaml
+`
+
+type OltProvsion struct {
+ Tosca_Definitions_Version string
+ Imports []string
+}
+*/
+
+func NewOltProvision(clli string, name string, deviceType string, host string, port int) OltProvsion {
+ o := OltProvsion{}
+ err := yaml.Unmarshal([]byte(templateData), &o)
+ if err != nil {
+ log.Printf("Error un-marshalling template data %v\n", err)
+ }
+
+ props := &o.TopologyTemplate.NodeTemplates.OltDevice.Properties
+ props.Name = name
+ props.Type = deviceType
+ props.Host = host
+ props.Port = port
+ props.NasID = clli
+ return o
+}
+
+func (olt *OltProvsion) ToYaml() (string, error) {
+ b, err := yaml.Marshal(olt)
+ return string(b), err
+}
diff --git a/models/tosca/addOlt_test.go b/models/tosca/addOlt_test.go
new file mode 100644
index 0000000..1b2f667
--- /dev/null
+++ b/models/tosca/addOlt_test.go
@@ -0,0 +1,79 @@
+/*
+ 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 tosca_test
+
+import (
+ "fmt"
+ "strings"
+ "testing"
+
+ "gerrit.opencord.org/abstract-olt/models/tosca"
+)
+
+var output = `tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+- custom_types/oltdevice.yaml
+- custom_types/onudevice.yaml
+- custom_types/ponport.yaml
+- custom_types/voltservice.yaml
+description: Create a simulated OLT Device in VOLTHA
+topology_template:
+ node_templates:
+ service#volt:
+ type: tosca.nodes.VOLTService
+ properties:
+ name: volt
+ must-exist: true
+ olt_device:
+ type: tosca.nodes.OLTDevice
+ properties:
+ name: myName
+ device_type: openolt
+ host: 192.168.1.1
+ port: 9191
+ outer_tpid: "0x8100"
+ uplink: "65536"
+ nas_id: my_clli
+ requirements:
+ - volt_service:
+ node: service#volt
+ relationship: tosca.relationships.BelongsToOne
+`
+
+var olt tosca.OltProvsion
+
+func TestAddOlt_NewOltProvsion(t *testing.T) {
+ fmt.Println("In TestAddOlt_NewOltProvsion")
+ olt = tosca.NewOltProvision("my_clli", "myName", "openolt", "192.168.1.1", 9191)
+ fmt.Printf("%v\n\n", olt)
+}
+
+func TestAddOlt_ToYaml(t *testing.T) {
+ y, err := olt.ToYaml()
+ if err != nil {
+ t.Fatalf("olt.ToYaml() failed with %v\n", err)
+ }
+ x := strings.Compare(y, output)
+ if x != 0 {
+ t.Fatal("ToYaml didn't produce the expected yaml")
+ }
+ fmt.Printf("Compare is %d\n", x)
+
+ fmt.Printf(y)
+ fmt.Println("******")
+ fmt.Print(output)
+ fmt.Println("******")
+}
diff --git a/models/tosca/addSubscriber.go b/models/tosca/addSubscriber.go
new file mode 100644
index 0000000..448569c
--- /dev/null
+++ b/models/tosca/addSubscriber.go
@@ -0,0 +1,89 @@
+/*
+ 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 tosca
+
+import (
+ "log"
+ "strings"
+
+ yaml "gopkg.in/yaml.v2"
+)
+
+var subSubscriberTemplate = `tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+ - custom_types/rcordsubscriber.yaml
+
+description: Pre-provsion a subscriber
+topology_template:
+ node_templates:
+ RG_NAME:
+ type: tosca.nodes.RCORDSubscriber
+ properties:
+ name:
+ status: pre-provisioned
+ c_tag:
+ s_tag:
+ onu_device:
+ nas_port_id:
+ circuit_id:
+ remote_id:`
+
+type SubscriberProvision struct {
+ ToscaDefinitionsVersion string `yaml:"tosca_definitions_version"`
+ Imports []string `yaml:"imports"`
+ Description string `yaml:"description"`
+ TopologyTemplate struct {
+ NodeTemplates struct {
+ RgName struct {
+ Type string `yaml:"type`
+ Properties struct {
+ Name string `yaml:"name"`
+ Status string `yaml:"status"`
+ CTag int `yaml:"c_tag"`
+ STag int `yaml:"s_tag"`
+ OnuDevice string `yaml:"onu_device"`
+ NasPortID string `yaml:"nas_port_id"`
+ CircuitID string `yaml:"circuit_id"`
+ RemoteID string `yaml:"remote_id"`
+ } `yaml:"properties"`
+ } `yaml:"RG_NAME"`
+ } `yaml:"node_templates"`
+ } `yaml:"topology_template"`
+}
+
+func NewSubscriberProvision(name string, cTag int, sTag int, onuDevice string, nasPortID string, circuitID string, remoteID string) SubscriberProvision {
+ s := SubscriberProvision{}
+ err := yaml.Unmarshal([]byte(subSubscriberTemplate), &s)
+ if err != nil {
+ log.Printf("Error un-marshalling template data %v\n", err)
+ }
+ props := &s.TopologyTemplate.NodeTemplates.RgName.Properties
+ props.Name = name
+ props.CTag = cTag
+ props.STag = sTag
+ props.OnuDevice = onuDevice
+ props.NasPortID = nasPortID
+ props.CircuitID = circuitID
+ props.RemoteID = remoteID
+ return s
+}
+func (sub *SubscriberProvision) ToYaml() (string, error) {
+ b, err := yaml.Marshal(sub)
+ ret := string(b)
+ name := sub.TopologyTemplate.NodeTemplates.RgName.Properties.Name
+ ret = strings.Replace(ret, "RG_NAME", name, -1)
+ return ret, err
+}
diff --git a/models/tosca/addSubscriber_test.go b/models/tosca/addSubscriber_test.go
new file mode 100644
index 0000000..0d48340
--- /dev/null
+++ b/models/tosca/addSubscriber_test.go
@@ -0,0 +1,75 @@
+/*
+ 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 tosca_test
+
+import (
+ "fmt"
+ "strings"
+ "testing"
+
+ "gerrit.opencord.org/abstract-olt/models/tosca"
+)
+
+var expectedOutput = `tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+- custom_types/rcordsubscriber.yaml
+description: Pre-provsion a subscriber
+topology_template:
+ node_templates:
+ myName:
+ type: tosca.nodes.RCORDSubscriber
+ properties:
+ name: myName
+ status: pre-provisioned
+ c_tag: 20
+ s_tag: 2
+ onu_device: onuSerialNumber
+ nas_port_id: /1/1/1/1/1.9
+ circuit_id: /1/1/1/1/1.9-CID
+ remote_id: myCilli
+`
+
+var sub tosca.SubscriberProvision
+
+func TestAddSubscriber_NewSubscriberProvision(t *testing.T) {
+ fmt.Println("Int TestAddSubscriber_NewSubscriberProvision")
+ sub = tosca.NewSubscriberProvision("myName", 20, 2, "onuSerialNumber", "/1/1/1/1/1.9", "/1/1/1/1/1.9-CID", "myCilli")
+ fmt.Printf("%v\n\n", sub)
+}
+
+func TestAddSubscriber_ToYaml(t *testing.T) {
+ y, err := sub.ToYaml()
+ if err != nil {
+ t.Fatalf("olt.ToYaml() failed with %v\n", err)
+ }
+
+ x := strings.Compare(y, expectedOutput)
+ if x != 0 {
+ fmt.Println("******")
+ fmt.Println(expectedOutput)
+ fmt.Println("******")
+ fmt.Println(y)
+ fmt.Println("******")
+ t.Fatal("ToYaml didn't produce the expected yaml")
+ }
+ fmt.Printf("Compare is %d\n", x)
+
+ fmt.Printf(y)
+ fmt.Println("******")
+ fmt.Print(output)
+ fmt.Println("******")
+}
diff --git a/models/tosca/provisionOnt.go b/models/tosca/provisionOnt.go
new file mode 100644
index 0000000..c83cc4d
--- /dev/null
+++ b/models/tosca/provisionOnt.go
@@ -0,0 +1,103 @@
+/*
+ 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 tosca
+
+import (
+ "fmt"
+ "net"
+ "strings"
+
+ yaml "gopkg.in/yaml.v2"
+)
+
+var ontTemplate = `tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+ - custom_types/attworkflowdriverwhitelistentry.yaml
+ - custom_types/attworkflowdriverservice.yaml
+description: Create an entry in the whitelist
+topology_template:
+ node_templates:
+ service#att:
+ type: tosca.nodes.AttWorkflowDriverService
+ properties:
+ name: att-workflow-driver
+ must-exist: true
+ ont:
+ type: tosca.nodes.AttWorkflowDriverWhiteListEntry
+ properties:
+ serial_number: ALPHe3d1cf57
+ pon_port_id: 536870912
+ device_id: of:000000000a4001ce
+ requirements:
+ - owner:
+ node: service#att
+ relationship: tosca.relationships.BelongsToOne`
+
+type OntProvision struct {
+ ToscaDefinitionsVersion string `yaml:"tosca_definitions_version"`
+ Imports []string `yaml:"imports"`
+ Description string `yaml:"description"`
+ TopologyTemplate struct {
+ NodeTemplates struct {
+ ServiceATT struct {
+ Type string `yaml:"type"`
+ Properties struct {
+ Name string `yaml:"name"`
+ MustExist bool `yaml:"must-exist"`
+ } `yaml:"properties"`
+ } `yaml:"service#att"`
+ Ont struct {
+ DeviceType string `yaml:"type"`
+ Properties struct {
+ SerialNumber string `yaml:"serial_number"`
+ PonPortID int `yaml:"pon_port_id"`
+ DeviceID string `yaml:"device_id"`
+ } `yaml:"properties"`
+ Requirements []struct {
+ Owner struct {
+ Node string `yaml:"node"`
+ Relationship string `yaml:"relationship"`
+ } `yaml:"owner"`
+ } `yaml:"requirements"`
+ } `yaml:"ont"`
+ } `yaml:"node_templates"`
+ } `yaml:"topology_template"`
+}
+
+func NewOntProvision(serialNumber string, oltIP net.IP, ponPortNumber int) OntProvision {
+ offset := 1 << 29
+ o := OntProvision{}
+ err := yaml.Unmarshal([]byte(ontTemplate), &o)
+ if err != nil {
+ }
+ props := &o.TopologyTemplate.NodeTemplates.Ont.Properties
+ props.PonPortID = offset + ponPortNumber
+ props.SerialNumber = serialNumber
+ ipNum := []byte(oltIP[12:16]) //only handling ipv4
+ ofID := fmt.Sprintf("of:00000000%0x", ipNum)
+ props.DeviceID = ofID
+ fmt.Printf("%v\n", o)
+ return o
+
+}
+func (ont *OntProvision) ToYaml() (string, error) {
+ b, err := yaml.Marshal(ont)
+ ret := string(b)
+ // Damn dirty hack but what are you going to do????
+ serialNumber := ont.TopologyTemplate.NodeTemplates.Ont.Properties.SerialNumber
+ ret = strings.Replace(ret, "ont", serialNumber, -1)
+ return ret, err
+}
diff --git a/models/tosca/provisionOnt_test.go b/models/tosca/provisionOnt_test.go
new file mode 100644
index 0000000..ff7cd85
--- /dev/null
+++ b/models/tosca/provisionOnt_test.go
@@ -0,0 +1,62 @@
+/*
+ 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 tosca_test
+
+import (
+ "fmt"
+ "net"
+ "testing"
+
+ "gerrit.opencord.org/abstract-olt/models/tosca"
+)
+
+var expected = `tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+- custom_types/attworkflowdriverwhitelistentry.yaml
+- custom_types/attworkflowdriverservice.yaml
+description: Create an entry in the whitelist
+topology_template:
+ node_templates:
+ service#att:
+ type: tosca.nodes.AttWorkflowDriverService
+ properties:
+ name: att-workflow-driver
+ must-exist: true
+ some_serial:
+ type: tosca.nodes.AttWorkflowDriverWhiteListEntry
+ properties:
+ serial_number: some_serial
+ pon_port_id: 536870914
+ device_id: of:00000000c0a8010b
+ requirements:
+ - owner:
+ node: service#att
+ relationship: tosca.relationships.BelongsToOne
+`
+var ont tosca.OntProvision
+
+//func NewOntProvision(serialNumber string, oltIP net.IP, ponPortNumber int) OntProvision {
+
+func TestOntProvision_NewOntProvision(t *testing.T) {
+ ont = tosca.NewOntProvision("some_serial", net.ParseIP("192.168.1.11"), 2)
+ ontYaml, _ := ont.ToYaml()
+ if ontYaml != expected {
+ t.Fatalf("Didn't generate the expected yaml\n Generated:\n%s \nExpected:\n%s\n", ontYaml, expected)
+ }
+ fmt.Println(ontYaml)
+ fmt.Println("******************")
+}