blob: 4252509608cf40dd0823a38f3a24aa8a18d41208 [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 (
20 "errors"
21 "github.com/google/gopacket/pcap"
22 "log"
23)
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 }
40 err := errors.New("No matched Ioinfo is found !")
41 log.Println(err)
42 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 }
51 err := errors.New("No matched Ioinfo is found !")
52 log.Println(err)
53 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 {
64 err := errors.New("No matched Ioinfo is found !")
65 log.Println(err)
66 return nil, err
67 }
68 return ioinfos, nil
69}