[VOL-3837] Checking that OnuId, AllocId and GemPorts are unique per PON
Validate that received flow carry valid GemPortId and AllocIds
Change-Id: I1b8928c7a9e580c9711f61320595a449df7c30f5
diff --git a/internal/bbsimctl/commands/helpers.go b/internal/bbsimctl/commands/helpers.go
new file mode 100644
index 0000000..f2a9ee1
--- /dev/null
+++ b/internal/bbsimctl/commands/helpers.go
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * 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 commands
+
+import (
+ pb "github.com/opencord/bbsim/api/bbsim"
+ "github.com/opencord/bbsim/internal/bbsimctl/config"
+ log "github.com/sirupsen/logrus"
+ "google.golang.org/grpc"
+)
+
+func connect() (pb.BBSimClient, *grpc.ClientConn) {
+ conn, err := grpc.Dial(config.GlobalConfig.Server, grpc.WithInsecure())
+
+ if err != nil {
+ log.Fatalf("did not connect: %v", err)
+ return nil, conn
+ }
+ return pb.NewBBSimClient(conn), conn
+}
diff --git a/internal/bbsimctl/commands/olt.go b/internal/bbsimctl/commands/olt.go
index bed3733..1789c86 100644
--- a/internal/bbsimctl/commands/olt.go
+++ b/internal/bbsimctl/commands/olt.go
@@ -22,6 +22,7 @@
"fmt"
"os"
"strconv"
+ "strings"
"github.com/jessevdk/go-flags"
"github.com/olekukonko/tablewriter"
@@ -29,12 +30,13 @@
"github.com/opencord/bbsim/internal/bbsimctl/config"
"github.com/opencord/cordctl/pkg/format"
log "github.com/sirupsen/logrus"
- "google.golang.org/grpc"
)
const (
- DEFAULT_OLT_DEVICE_HEADER_FORMAT = "table{{ .ID }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}\t{{ .IP }}"
- DEFAULT_PORT_HEADER_FORMAT = "table{{ .ID }}\t{{ .OperState }}"
+ DEFAULT_OLT_DEVICE_HEADER_FORMAT = "table{{ .ID }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}\t{{ .IP }}"
+ DEFAULT_OLT_RESOURCES_HEADER_FORMAT = "table{{ .Type }}\t{{ .PonPortId }}\t{{ .OnuId }}\t{{ .PortNo }}\t{{ .ResourceId }}\t{{ .FlowId }}"
+ DEFAULT_NNI_PORT_HEADER_FORMAT = "table{{ .ID }}\t{{ .OperState }}\t{{ .InternalState }}\t{{ .PacketCount }}"
+ DEFAULT_PON_PORT_HEADER_FORMAT = "table{{ .ID }}\t{{ .OperState }}\t{{ .InternalState }}\t{{ .PacketCount }}\t{{ .AllocatedOnuIds }}\t{{ .AllocatedGemPorts }}\t{{ .AllocatedAllocIds }}"
)
type OltGet struct{}
@@ -64,8 +66,16 @@
type OltShutdownAllOnus struct{}
+type oltResourcesType string
+type OltResources struct {
+ Args struct {
+ Type oltResourcesType
+ } `positional-args:"yes" required:"yes"`
+}
+
type oltOptions struct {
Get OltGet `command:"get"`
+ GetResources OltResources `command:"resources"`
NNI OltNNIs `command:"nnis"`
PON OltPONs `command:"pons"`
Shutdown OltShutdown `command:"shutdown"`
@@ -85,19 +95,12 @@
}
func getOLT() *pb.Olt {
- conn, err := grpc.Dial(config.GlobalConfig.Server, grpc.WithInsecure())
- if err != nil {
- log.Fatalf("did not connect: %v", err)
- return nil
- }
+ client, conn := connect()
defer conn.Close()
- c := pb.NewBBSimClient(conn)
-
- // Contact the server and print out its response.
ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
defer cancel()
- olt, err := c.GetOlt(ctx, &pb.Empty{})
+ olt, err := client.GetOlt(ctx, &pb.Empty{})
if err != nil {
log.Fatalf("could not get OLT: %v", err)
return nil
@@ -120,12 +123,34 @@
return nil
}
+func (o *OltResources) Execute(args []string) error {
+ client, conn := connect()
+ defer conn.Close()
+
+ resourceType := pb.OltAllocatedResourceType_Type_value[string(o.Args.Type)]
+
+ ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
+ defer cancel()
+ resources, err := client.GetOltAllocatedResources(ctx, &pb.OltAllocatedResourceType{Type: pb.OltAllocatedResourceType_Type(resourceType)})
+
+ if err != nil {
+ log.Fatalf("could not get OLT resources: %v", err)
+ return nil
+ }
+
+ tableFormat := format.Format(DEFAULT_OLT_RESOURCES_HEADER_FORMAT)
+ if err := tableFormat.Execute(os.Stdout, true, resources.Resources); err != nil {
+ return err
+ }
+ return nil
+}
+
func (o *OltNNIs) Execute(args []string) error {
olt := getOLT()
printOltHeader("NNI Ports for", olt)
- tableFormat := format.Format(DEFAULT_PORT_HEADER_FORMAT)
+ tableFormat := format.Format(DEFAULT_NNI_PORT_HEADER_FORMAT)
_ = tableFormat.Execute(os.Stdout, true, olt.NNIPorts)
return nil
@@ -136,7 +161,7 @@
printOltHeader("PON Ports for", olt)
- tableFormat := format.Format(DEFAULT_PORT_HEADER_FORMAT)
+ tableFormat := format.Format(DEFAULT_PON_PORT_HEADER_FORMAT)
_ = tableFormat.Execute(os.Stdout, true, olt.PONPorts)
return nil
@@ -354,3 +379,13 @@
fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message))
return nil
}
+
+func (rt *oltResourcesType) Complete(match string) []flags.Completion {
+ list := make([]flags.Completion, 0)
+ for k := range pb.OltAllocatedResourceType_Type_value {
+ if strings.HasPrefix(k, strings.ToUpper(match)) && k != pb.OltAllocatedResourceType_UNKNOWN.String() {
+ list = append(list, flags.Completion{Item: k})
+ }
+ }
+ return list
+}
diff --git a/internal/bbsimctl/commands/onu.go b/internal/bbsimctl/commands/onu.go
index 78923e0..33bd5ef 100644
--- a/internal/bbsimctl/commands/onu.go
+++ b/internal/bbsimctl/commands/onu.go
@@ -30,7 +30,6 @@
"github.com/opencord/bbsim/internal/bbsimctl/config"
"github.com/opencord/cordctl/pkg/format"
log "github.com/sirupsen/logrus"
- "google.golang.org/grpc"
)
const (
@@ -127,16 +126,6 @@
_, _ = parser.AddCommand("onu", "ONU Commands", "Commands to query and manipulate ONU devices", &ONUOptions{})
}
-func connect() (pb.BBSimClient, *grpc.ClientConn) {
- conn, err := grpc.Dial(config.GlobalConfig.Server, grpc.WithInsecure())
-
- if err != nil {
- log.Fatalf("did not connect: %v", err)
- return nil, conn
- }
- return pb.NewBBSimClient(conn), conn
-}
-
func getONUs() *pb.ONUs {
client, conn := connect()