Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package core |
| 18 | |
| 19 | import ( |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 20 | "errors" |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 21 | "strconv" |
| 22 | "sync" |
| 23 | "time" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 24 | "gerrit.opencord.org/voltha-bbsim/device" |
| 25 | "gerrit.opencord.org/voltha-bbsim/protos" |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 26 | "gerrit.opencord.org/voltha-bbsim/common" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 27 | "gerrit.opencord.org/voltha-bbsim/setup" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 28 | "github.com/google/gopacket" |
| 29 | "github.com/google/gopacket/layers" |
| 30 | "github.com/google/gopacket/pcap" |
| 31 | "google.golang.org/grpc" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | type Mode int |
| 35 | |
| 36 | const MAX_ONUS_PER_PON = 64 // This value should be the same with the value in AdapterPlatrorm class |
| 37 | |
| 38 | const ( |
| 39 | DEFAULT Mode = iota |
| 40 | AAA |
| 41 | BOTH |
| 42 | ) |
| 43 | |
| 44 | type Server struct { |
| 45 | Olt *device.Olt |
| 46 | Onumap map[uint32][]*device.Onu |
| 47 | Ioinfos []*Ioinfo |
| 48 | Endchan chan int |
| 49 | Mode Mode |
| 50 | AAAWait int |
| 51 | DhcpWait int |
| 52 | DhcpServerIP string |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 53 | Delay int |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 54 | gRPCserver *grpc.Server |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 55 | VethEnv []string |
| 56 | TestFlag bool |
| 57 | Processes []string |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 58 | EnableServer *openolt.Openolt_EnableIndicationServer |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 59 | CtagMap map[string]uint32 |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | type Packet struct { |
| 63 | Info *Ioinfo |
| 64 | Pkt gopacket.Packet |
| 65 | } |
| 66 | |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 67 | func (s *Server) Initialize() { |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 68 | s.VethEnv = []string{} |
| 69 | s.Endchan = make(chan int) |
| 70 | s.TestFlag = false |
| 71 | s.Processes = []string{} |
| 72 | s.Ioinfos = []*Ioinfo{} |
| 73 | } |
| 74 | |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 75 | func Create(oltid uint32, npon uint32, nonus uint32, aaawait int, dhcpwait int, ip string, delay int, g *grpc.Server, mode Mode, e chan int) *Server { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 76 | s := new(Server) |
| 77 | s.Olt = device.CreateOlt(oltid, npon, 1) |
| 78 | nnni := s.Olt.NumNniIntf |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 79 | logger.Info("OLT ID: %d was retrieved.\n", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 80 | s.Onumap = make(map[uint32][]*device.Onu) |
| 81 | s.AAAWait = aaawait |
| 82 | s.DhcpWait = dhcpwait |
| 83 | s.DhcpServerIP = ip |
| 84 | s.gRPCserver = g |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 85 | s.Delay = delay |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 86 | s.Mode = mode |
| 87 | s.Endchan = e |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 88 | s.VethEnv = []string{} |
| 89 | s.TestFlag = false |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 90 | for intfid := nnni; intfid < npon+nnni; intfid++ { |
| 91 | s.Onumap[intfid] = device.CreateOnus(oltid, intfid, nonus, nnni) |
| 92 | } |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 93 | s.EnableServer = new(openolt.Openolt_EnableIndicationServer) |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 94 | |
| 95 | //TODO: To be fixed |
| 96 | s.CtagMap = make(map[string]uint32) |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 97 | for i := 0; i < MAX_ONUS_PER_PON; i++ { |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 98 | oltid := s.Olt.ID |
| 99 | intfid := uint32(1) |
| 100 | sn := convB2S(device.CreateSN(oltid, intfid, uint32(i))) |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 101 | s.CtagMap[sn] = uint32(900 + i) // This is hard coded for BBWF |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 102 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 103 | return s |
| 104 | } |
| 105 | |
| 106 | func (s *Server) activateOLT(stream openolt.Openolt_EnableIndicationServer) error { |
| 107 | // Activate OLT |
| 108 | olt := s.Olt |
| 109 | oltid := olt.ID |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 110 | wg := &sync.WaitGroup{} |
| 111 | |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 112 | if err := sendOltIndUp(stream, olt); err != nil { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 113 | return err |
| 114 | } |
| 115 | olt.OperState = "up" |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 116 | *olt.InternalState = device.OLT_UP |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 117 | logger.Info("OLT %s sent OltInd.\n", olt.Name) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 118 | |
| 119 | // OLT sends Interface Indication to Adapter |
| 120 | if err := sendIntfInd(stream, olt); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 121 | logger.Error("Fail to sendIntfInd: %v\n", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 122 | return err |
| 123 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 124 | logger.Info("OLT %s sent IntfInd.\n", olt.Name) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 125 | |
| 126 | // OLT sends Operation Indication to Adapter after activating each interface |
| 127 | //time.Sleep(IF_UP_TIME * time.Second) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 128 | *olt.InternalState = device.PONIF_UP |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 129 | if err := sendOperInd(stream, olt); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 130 | logger.Error("Fail to sendOperInd: %v\n", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 131 | return err |
| 132 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 133 | logger.Info("OLT %s sent OperInd.\n", olt.Name) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 134 | |
| 135 | // OLT sends ONU Discover Indication to Adapter after ONU discovery |
| 136 | for intfid, _ := range s.Onumap { |
| 137 | device.UpdateOnusOpStatus(intfid, s.Onumap[intfid], "up") |
| 138 | } |
| 139 | |
| 140 | for intfid, _ := range s.Onumap { |
| 141 | sendOnuDiscInd(stream, s.Onumap[intfid]) |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 142 | logger.Info("OLT id:%d sent ONUDiscInd.\n", olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | // OLT Sends OnuInd after waiting all of those ONUs up |
| 146 | for { |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 147 | if s.IsAllOnuActive(s.Onumap) { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 148 | break |
| 149 | } |
| 150 | } |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 151 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 152 | for intfid, _ := range s.Onumap { |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 153 | sendOnuInd(stream, s.Onumap[intfid], s.Delay) |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 154 | logger.Info("OLT id:%d sent ONUInd.\n", olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | if s.Mode == DEFAULT { |
| 158 | //EnableIndication's stream should be kept even after activateOLT() is finished. |
| 159 | //Otherwise, OpenOLT adapter sends EnableIndication again. |
| 160 | <-s.Endchan |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 161 | logger.Debug("core server thread receives close ") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 162 | } else if s.Mode == AAA || s.Mode == BOTH { |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 163 | s.TestFlag = true |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 164 | var err error |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 165 | s.Ioinfos, s.VethEnv, err = createIoinfos(oltid, s.VethEnv, s.Onumap) |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 166 | logger.Debug("s.VethEnv:%v", s.VethEnv) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 167 | if err != nil { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 168 | return err |
| 169 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 170 | |
| 171 | errchan := make(chan error) |
| 172 | go func() { |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 173 | <-errchan |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 174 | close(s.Endchan) |
| 175 | }() |
| 176 | |
| 177 | wg.Add(1) |
| 178 | go func() { |
| 179 | defer func() { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 180 | logger.Debug("runPacketInDaemon Done") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 181 | wg.Done() |
| 182 | }() |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 183 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 184 | err := s.runPacketInDaemon(stream) |
| 185 | if err != nil { |
| 186 | errchan <- err |
| 187 | return |
| 188 | } |
| 189 | }() |
| 190 | |
| 191 | wg.Add(1) |
| 192 | go func() { |
| 193 | defer func() { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 194 | logger.Debug("exeAAATest Done") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 195 | wg.Done() |
| 196 | }() |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 197 | |
| 198 | err = s.exeAAATest() |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 199 | if err != nil { |
| 200 | errchan <- err |
| 201 | return |
| 202 | } |
Keita NISHIMOTO | c864da2 | 2018-10-15 22:41:42 +0900 | [diff] [blame] | 203 | |
| 204 | if s.Mode == BOTH { |
| 205 | go func() { |
| 206 | defer func() { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 207 | logger.Debug("exeDHCPTest Done") |
Keita NISHIMOTO | c864da2 | 2018-10-15 22:41:42 +0900 | [diff] [blame] | 208 | }() |
Keita NISHIMOTO | c864da2 | 2018-10-15 22:41:42 +0900 | [diff] [blame] | 209 | |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 210 | err := s.exeDHCPTest() |
Keita NISHIMOTO | c864da2 | 2018-10-15 22:41:42 +0900 | [diff] [blame] | 211 | if err != nil { |
| 212 | errchan <- err |
| 213 | return |
| 214 | } |
| 215 | }() |
| 216 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 217 | }() |
| 218 | wg.Wait() |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 219 | cleanUpVeths(s.VethEnv) // Grace teardown |
| 220 | pnames := s.Processes |
| 221 | killProcesses(pnames) |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 222 | logger.Debug("Grace shutdown down") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 223 | } |
| 224 | return nil |
| 225 | } |
| 226 | |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 227 | func createIoinfos(oltid uint32, vethenv []string, onumap map[uint32][]*device.Onu) ([]*Ioinfo, []string, error) { |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 228 | ioinfos := []*Ioinfo{} |
| 229 | var err error |
| 230 | for intfid, _ := range onumap { |
| 231 | for i := 0; i < len(onumap[intfid]); i++ { |
| 232 | var handler *pcap.Handle |
| 233 | onuid := onumap[intfid][i].OnuID |
| 234 | uniup, unidw := makeUniName(oltid, intfid, onuid) |
| 235 | if handler, vethenv, err = setupVethHandler(uniup, unidw, vethenv); err != nil { |
| 236 | return ioinfos, vethenv, err |
| 237 | } |
| 238 | iinfo := Ioinfo{name: uniup, iotype: "uni", ioloc: "inside", intfid: intfid, onuid: onuid, handler: handler} |
| 239 | ioinfos = append(ioinfos, &iinfo) |
| 240 | oinfo := Ioinfo{name: unidw, iotype: "uni", ioloc: "outside", intfid: intfid, onuid: onuid, handler: nil} |
| 241 | ioinfos = append(ioinfos, &oinfo) |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | var handler *pcap.Handle |
| 246 | nniup, nnidw := makeNniName(oltid) |
| 247 | if handler, vethenv, err = setupVethHandler(nniup, nnidw, vethenv); err != nil { |
| 248 | return ioinfos, vethenv, err |
| 249 | } |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 250 | |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 251 | iinfo := Ioinfo{name: nnidw, iotype: "nni", ioloc: "inside", intfid: 1, handler: handler} |
| 252 | ioinfos = append(ioinfos, &iinfo) |
| 253 | oinfo := Ioinfo{name: nniup, iotype: "nni", ioloc: "outside", intfid: 1, handler: nil} |
| 254 | ioinfos = append(ioinfos, &oinfo) |
| 255 | return ioinfos, vethenv, nil |
| 256 | } |
| 257 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 258 | func (s *Server) runPacketInDaemon(stream openolt.Openolt_EnableIndicationServer) error { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 259 | logger.Debug("runPacketInDaemon Start") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 260 | unichannel := make(chan Packet, 2048) |
| 261 | flag := false |
| 262 | |
| 263 | for intfid, _ := range s.Onumap { |
| 264 | for _, onu := range s.Onumap[intfid] { //TODO: should be updated for multiple-Interface |
| 265 | onuid := onu.OnuID |
| 266 | ioinfo, err := s.identifyUniIoinfo("inside", intfid, onuid) |
| 267 | if err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 268 | logger.Error("Fail to identifyUniIoinfo (onuid: %d): %v\n", onuid, err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 269 | return err |
| 270 | } |
| 271 | uhandler := ioinfo.handler |
| 272 | defer uhandler.Close() |
| 273 | go RecvWorker(ioinfo, uhandler, unichannel) |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | ioinfo, err := s.identifyNniIoinfo("inside") |
| 278 | if err != nil { |
| 279 | return err |
| 280 | } |
| 281 | nhandler := ioinfo.handler |
| 282 | defer nhandler.Close() |
| 283 | nnichannel := make(chan Packet, 32) |
| 284 | go RecvWorker(ioinfo, nhandler, nnichannel) |
| 285 | |
| 286 | data := &openolt.Indication_PktInd{} |
| 287 | for { |
| 288 | select { |
| 289 | case unipkt := <-unichannel: |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 290 | logger.Debug("Received packet in grpc Server from UNI.") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 291 | if unipkt.Info == nil || unipkt.Info.iotype != "uni" { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 292 | logger.Info("WARNING: This packet does not come from UNI ") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 293 | continue |
| 294 | } |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 295 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 296 | intfid := unipkt.Info.intfid |
| 297 | onuid := unipkt.Info.onuid |
| 298 | gemid, _ := getGemPortID(intfid, onuid) |
| 299 | pkt := unipkt.Pkt |
| 300 | layerEth := pkt.Layer(layers.LayerTypeEthernet) |
| 301 | le, _ := layerEth.(*layers.Ethernet) |
| 302 | ethtype := le.EthernetType |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 303 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 304 | if ethtype == 0x888e { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 305 | logger.Debug("Received upstream packet is EAPOL.") |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 306 | //log.Println(unipkt.Pkt.Dump()) |
| 307 | //log.Println(pkt.Dump()) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 308 | } else if layerDHCP := pkt.Layer(layers.LayerTypeDHCPv4); layerDHCP != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 309 | logger.Debug("Received upstream packet is DHCP.") |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 310 | |
| 311 | //C-TAG |
| 312 | onu, _ := s.getOnuByID(onuid) |
| 313 | sn := convB2S(onu.SerialNumber.VendorSpecific) |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 314 | if ctag, ok := s.CtagMap[sn]; ok == true { |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 315 | tagpkt, err := PushVLAN(pkt, uint16(ctag)) |
| 316 | if err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 317 | logger.Error("Fail to tag C-tag") |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 318 | } else { |
| 319 | pkt = tagpkt |
| 320 | } |
| 321 | } else { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 322 | logger.Error("Could not find the onuid %d (SN: %s) in CtagMap %v!\n", onuid, sn, s.CtagMap) |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 323 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 324 | } else { |
| 325 | continue |
| 326 | } |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 327 | |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 328 | logger.Debug("sendPktInd intfid:%d (onuid: %d) gemid:%d\n", intfid, onuid, gemid) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 329 | data = &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{IntfType: "pon", IntfId: intfid, GemportId: gemid, Pkt: pkt.Data()}} |
| 330 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 331 | logger.Error("Fail to send PktInd indication. %v\n", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 332 | return err |
| 333 | } |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 334 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 335 | case nnipkt := <-nnichannel: |
| 336 | if nnipkt.Info == nil || nnipkt.Info.iotype != "nni" { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 337 | logger.Info("WARNING: This packet does not come from NNI ") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 338 | continue |
| 339 | } |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 340 | |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 341 | logger.Debug("Received packet in grpc Server from NNI.") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 342 | intfid := nnipkt.Info.intfid |
| 343 | pkt := nnipkt.Pkt |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 344 | logger.Info("sendPktInd intfid:%d\n", intfid) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 345 | data = &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{IntfType: "nni", IntfId: intfid, Pkt: pkt.Data()}} |
| 346 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 347 | logger.Error("Fail to send PktInd indication. %v\n", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 348 | return err |
| 349 | } |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 350 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 351 | case <-s.Endchan: |
| 352 | if flag == false { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 353 | logger.Debug("PacketInDaemon thread receives close ") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 354 | close(unichannel) |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 355 | logger.Debug("Closed unichannel ") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 356 | close(nnichannel) |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 357 | logger.Debug("Closed nnichannel ") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 358 | flag = true |
| 359 | return nil |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | return nil |
| 364 | } |
| 365 | |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 366 | func (s *Server) exeAAATest() error { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 367 | logger.Info("exeAAATest stands by....") |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 368 | infos, err := s.getUniIoinfos("outside") |
| 369 | if err != nil { |
| 370 | return err |
| 371 | } |
| 372 | |
| 373 | univeths := []string{} |
| 374 | for _, info := range infos { |
| 375 | univeths = append(univeths, info.name) |
| 376 | } |
| 377 | |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 378 | for { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 379 | select { |
| 380 | case <-s.Endchan: |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 381 | logger.Debug("exeAAATest thread receives close ") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 382 | return nil |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 383 | case <-time.After(time.Second * time.Duration(s.AAAWait)): |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 384 | err = setup.ActivateWPASups(univeths, s.Delay) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 385 | if err != nil { |
| 386 | return err |
| 387 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 388 | logger.Info("WPA Supplicants are successfully activated ") |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 389 | s.Processes = append(s.Processes, "wpa_supplicant") |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 390 | logger.Debug("Running Process:%v", s.Processes) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 391 | return nil |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 392 | } |
| 393 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 394 | return nil |
| 395 | } |
| 396 | |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 397 | func (s *Server) exeDHCPTest() error { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 398 | logger.Info("exeDHCPTest stands by....") |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 399 | info, err := s.identifyNniIoinfo("outside") |
| 400 | |
| 401 | if err != nil { |
| 402 | return err |
| 403 | } |
| 404 | |
| 405 | err = setup.ActivateDHCPServer(info.name, s.DhcpServerIP) |
| 406 | if err != nil { |
| 407 | return err |
| 408 | } |
| 409 | s.Processes = append(s.Processes, "dhcpd") |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 410 | logger.Debug("Running Process:%v", s.Processes) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 411 | |
| 412 | infos, err := s.getUniIoinfos("outside") |
| 413 | if err != nil { |
| 414 | return err |
| 415 | } |
| 416 | |
| 417 | univeths := []string{} |
| 418 | for _, info := range infos { |
| 419 | univeths = append(univeths, info.name) |
| 420 | } |
| 421 | |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 422 | for { |
Keita NISHIMOTO | c864da2 | 2018-10-15 22:41:42 +0900 | [diff] [blame] | 423 | select { |
| 424 | case <-s.Endchan: |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 425 | logger.Debug("exeDHCPTest thread receives close ") |
Keita NISHIMOTO | c864da2 | 2018-10-15 22:41:42 +0900 | [diff] [blame] | 426 | return nil |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 427 | case <-time.After(time.Second * time.Duration(s.DhcpWait)): |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 428 | err = setup.ActivateDHCPClients(univeths, s.Delay) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 429 | if err != nil { |
| 430 | return err |
| 431 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 432 | logger.Info("DHCP clients are successfully activated ") |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 433 | s.Processes = append(s.Processes, "dhclient") |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 434 | logger.Debug("Running Process:%v", s.Processes) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 435 | return nil |
Keita NISHIMOTO | c864da2 | 2018-10-15 22:41:42 +0900 | [diff] [blame] | 436 | } |
| 437 | } |
Keita NISHIMOTO | c864da2 | 2018-10-15 22:41:42 +0900 | [diff] [blame] | 438 | return nil |
| 439 | } |
| 440 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 441 | func (s *Server) onuPacketOut(intfid uint32, onuid uint32, rawpkt gopacket.Packet) error { |
| 442 | layerEth := rawpkt.Layer(layers.LayerTypeEthernet) |
| 443 | if layerEth != nil { |
| 444 | pkt, _ := layerEth.(*layers.Ethernet) |
| 445 | ethtype := pkt.EthernetType |
| 446 | if ethtype == 0x888e { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 447 | logger.Debug("Received downstream packet is EAPOL.") |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 448 | //log.Println(rawpkt.Dump()) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 449 | } else if layerDHCP := rawpkt.Layer(layers.LayerTypeDHCPv4); layerDHCP != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 450 | logger.Debug("Received downstream packet is DHCP.") |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 451 | //log.Println(rawpkt.Dump()) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 452 | rawpkt, _, _ = PopVLAN(rawpkt) |
| 453 | rawpkt, _, _ = PopVLAN(rawpkt) |
| 454 | } else { |
| 455 | return nil |
| 456 | } |
| 457 | ioinfo, err := s.identifyUniIoinfo("inside", intfid, onuid) |
| 458 | if err != nil { |
| 459 | return err |
| 460 | } |
| 461 | handle := ioinfo.handler |
| 462 | SendUni(handle, rawpkt) |
| 463 | return nil |
| 464 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 465 | logger.Info("WARNING: Received packet is not supported") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 466 | return nil |
| 467 | } |
| 468 | |
| 469 | func (s *Server) uplinkPacketOut(rawpkt gopacket.Packet) error { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 470 | poppkt, _, err := PopVLAN(rawpkt) |
| 471 | poppkt, _, err = PopVLAN(poppkt) |
| 472 | if err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 473 | logger.Error("%s", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 474 | return err |
| 475 | } |
| 476 | ioinfo, err := s.identifyNniIoinfo("inside") |
| 477 | if err != nil { |
| 478 | return err |
| 479 | } |
| 480 | handle := ioinfo.handler |
| 481 | SendNni(handle, poppkt) |
| 482 | return nil |
| 483 | } |
| 484 | |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 485 | func (s *Server) IsAllOnuActive(regonus map[uint32][]*device.Onu) bool { |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 486 | for _, onus := range regonus { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 487 | for _, onu := range onus { |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 488 | if onu.GetIntStatus() != device.ONU_ACTIVATED { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 489 | return false |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | return true |
| 494 | } |
| 495 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 496 | func getGemPortID(intfid uint32, onuid uint32) (uint32, error) { |
| 497 | idx := uint32(0) |
| 498 | return 1024 + (((MAX_ONUS_PER_PON*intfid + onuid - 1) * 7) + idx), nil |
| 499 | //return uint32(1032 + 8 * (vid - 1)), nil |
| 500 | } |
| 501 | |
| 502 | func (s *Server) getOnuBySN(sn *openolt.SerialNumber) (*device.Onu, error) { |
| 503 | for _, onus := range s.Onumap { |
| 504 | for _, onu := range onus { |
| 505 | if device.ValidateSN(*sn, *onu.SerialNumber) { |
| 506 | return onu, nil |
| 507 | } |
| 508 | } |
| 509 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 510 | err := errors.New("No mathced SN is found ") |
| 511 | logger.Error("%s", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 512 | return nil, err |
| 513 | } |
| 514 | |
| 515 | func (s *Server) getOnuByID(onuid uint32) (*device.Onu, error) { |
| 516 | for _, onus := range s.Onumap { |
| 517 | for _, onu := range onus { |
| 518 | if onu.OnuID == onuid { |
| 519 | return onu, nil |
| 520 | } |
| 521 | } |
| 522 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 523 | err := errors.New("No matched OnuID is found ") |
| 524 | logger.Error("%s", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 525 | return nil, err |
| 526 | } |
| 527 | |
| 528 | func makeUniName(oltid uint32, intfid uint32, onuid uint32) (upif string, dwif string) { |
| 529 | upif = setup.UNI_VETH_UP_PFX + strconv.Itoa(int(oltid)) + "_" + strconv.Itoa(int(intfid)) + "_" + strconv.Itoa(int(onuid)) |
| 530 | dwif = setup.UNI_VETH_DW_PFX + strconv.Itoa(int(oltid)) + "_" + strconv.Itoa(int(intfid)) + "_" + strconv.Itoa(int(onuid)) |
| 531 | return |
| 532 | } |
| 533 | |
| 534 | func makeNniName(oltid uint32) (upif string, dwif string) { |
| 535 | upif = setup.NNI_VETH_UP_PFX + strconv.Itoa(int(oltid)) |
| 536 | dwif = setup.NNI_VETH_DW_PFX + strconv.Itoa(int(oltid)) |
| 537 | return |
| 538 | } |
| 539 | |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 540 | func cleanUpVeths(vethenv []string) error { |
| 541 | if len(vethenv) > 0 { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 542 | logger.Debug("cleanUpVeths called ") |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 543 | setup.TearVethDown(vethenv) |
| 544 | } |
| 545 | return nil |
| 546 | } |
| 547 | |
| 548 | func killProcesses(pnames []string) error { |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 549 | for _, pname := range pnames { |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 550 | setup.KillProcess(pname) |
| 551 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 552 | return nil |
| 553 | } |
| 554 | |
| 555 | func setupVethHandler(inveth string, outveth string, vethenv []string) (*pcap.Handle, []string, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 556 | logger.Debug("SetupVethHandler(%s, %s) called ", inveth, outveth) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 557 | err1 := setup.CreateVethPairs(inveth, outveth) |
| 558 | vethenv = append(vethenv, inveth) |
| 559 | if err1 != nil { |
| 560 | setup.RemoveVeths(vethenv) |
| 561 | return nil, vethenv, err1 |
| 562 | } |
| 563 | handler, err2 := getVethHandler(inveth) |
| 564 | if err2 != nil { |
| 565 | setup.RemoveVeths(vethenv) |
| 566 | return nil, vethenv, err2 |
| 567 | } |
| 568 | return handler, vethenv, nil |
| 569 | } |
| 570 | |
| 571 | func getVethHandler(vethname string) (*pcap.Handle, error) { |
| 572 | var ( |
| 573 | device string = vethname |
| 574 | snapshot_len int32 = 1518 |
| 575 | promiscuous bool = false |
| 576 | err error |
| 577 | timeout time.Duration = pcap.BlockForever |
| 578 | ) |
| 579 | handle, err := pcap.OpenLive(device, snapshot_len, promiscuous, timeout) |
| 580 | if err != nil { |
| 581 | return nil, err |
| 582 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 583 | logger.Debug("Server handle is created for %s\n", vethname) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 584 | return handle, nil |
| 585 | } |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 586 | |
| 587 | func convB2S(b []byte) string { |
| 588 | s := "" |
| 589 | for _, i := range b { |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 590 | s = s + strconv.FormatInt(int64(i/16), 16) + strconv.FormatInt(int64(i%16), 16) |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 591 | } |
| 592 | return s |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 593 | } |