blob: 21e1b9a25aafc62eb0cc210d48082de1d3ea6c68 [file] [log] [blame]
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package core
18
19import (
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090020 "github.com/google/gopacket/pcap"
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090021 "gerrit.opencord.org/voltha-bbsim/common"
Keita NISHIMOTOb8417492018-10-19 17:37:38 +090022 "errors"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090023)
24
25type Ioinfo struct {
26 name string
27 iotype string //nni or uni
28 ioloc string //inside or outsode
29 intfid uint32
30 onuid uint32
31 handler *pcap.Handle
32}
33
34func (s *Server) identifyUniIoinfo(ioloc string, intfid uint32, onuid uint32) (*Ioinfo, error) {
35 for _, ioinfo := range s.Ioinfos {
36 if ioinfo.iotype == "uni" && ioinfo.intfid == intfid && ioinfo.onuid == onuid && ioinfo.ioloc == ioloc {
37 return ioinfo, nil
38 }
39 }
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090040 err := errors.New("No matched Ioinfo is found")
41 logger.Error("%s", err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090042 return nil, err
43}
44
45func (s *Server) identifyNniIoinfo(ioloc string) (*Ioinfo, error) {
46 for _, ioinfo := range s.Ioinfos {
47 if ioinfo.iotype == "nni" && ioinfo.ioloc == ioloc {
48 return ioinfo, nil
49 }
50 }
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090051 err := errors.New("No matched Ioinfo is found")
52 logger.Error("%s", err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090053 return nil, err
54}
55
56func (s *Server) getUniIoinfos(ioloc string) ([]*Ioinfo, error) {
57 ioinfos := []*Ioinfo{}
58 for _, ioinfo := range s.Ioinfos {
59 if ioinfo.iotype == "uni" && ioinfo.ioloc == ioloc {
60 ioinfos = append(ioinfos, ioinfo)
61 }
62 }
63 if len(ioinfos) == 0 {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090064 err := errors.New("No matched Ioinfo is found")
65 logger.Error("%s", err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090066 return nil, err
67 }
68 return ioinfos, nil
69}