Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [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 devices |
| 18 | |
| 19 | import ( |
| 20 | "github.com/google/gopacket" |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 21 | "github.com/opencord/bbsim/internal/bbsim/packetHandlers" |
Matteo Scandolo | 3de9de0 | 2019-11-14 13:40:03 -0800 | [diff] [blame] | 22 | "github.com/opencord/voltha-protos/v2/go/openolt" |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 23 | "net" |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | type MessageType int |
| 27 | |
| 28 | const ( |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 29 | OltIndication MessageType = 0 |
| 30 | NniIndication MessageType = 1 |
| 31 | PonIndication MessageType = 2 |
| 32 | OnuDiscIndication MessageType = 3 |
| 33 | OnuIndication MessageType = 4 |
| 34 | OMCI MessageType = 5 |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 35 | FlowAdd MessageType = 6 |
| 36 | FlowRemoved MessageType = 18 |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 37 | OnuPacketOut MessageType = 9 |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 38 | |
| 39 | // BBR messages |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 40 | OmciIndication MessageType = 10 // this are OMCI messages going from the OLT to VOLTHA |
| 41 | SendEapolFlow MessageType = 11 |
| 42 | SendDhcpFlow MessageType = 12 |
| 43 | OnuPacketIn MessageType = 13 |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 44 | |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 45 | //IGMP |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 46 | IGMPMembershipReportV2 MessageType = 14 // Version 2 Membership Report (JOIN) |
| 47 | IGMPLeaveGroup MessageType = 15 // Leave Group |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 48 | |
Matteo Scandolo | d7cc6d3 | 2020-02-26 16:51:12 -0800 | [diff] [blame] | 49 | AlarmIndication MessageType = 16 // message data is an openolt.AlarmIndication |
| 50 | IGMPMembershipReportV3 MessageType = 17 // Version 3 Membership Report |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 51 | ) |
| 52 | |
| 53 | func (m MessageType) String() string { |
| 54 | names := [...]string{ |
| 55 | "OltIndication", |
| 56 | "NniIndication", |
| 57 | "PonIndication", |
| 58 | "OnuDiscIndication", |
| 59 | "OnuIndication", |
| 60 | "OMCI", |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 61 | "FlowAdd", |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 62 | "StartEAPOL", |
| 63 | "StartDHCP", |
| 64 | "OnuPacketOut", |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 65 | "OmciIndication", |
| 66 | "SendEapolFlow", |
| 67 | "SendDhcpFlow", |
| 68 | "OnuPacketIn", |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 69 | "IGMPMembershipReportV2", |
| 70 | "IGMPLeaveGroup", |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 71 | "IGMPMembershipReportV3", |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 72 | "FlowRemoved", |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 73 | } |
| 74 | return names[m] |
| 75 | } |
| 76 | |
| 77 | type Message struct { |
| 78 | Type MessageType |
| 79 | Data interface{} |
| 80 | } |
| 81 | |
| 82 | type OltIndicationMessage struct { |
| 83 | OperState OperState |
| 84 | } |
| 85 | |
| 86 | type NniIndicationMessage struct { |
| 87 | OperState OperState |
| 88 | NniPortID uint32 |
| 89 | } |
| 90 | |
| 91 | type PonIndicationMessage struct { |
| 92 | OperState OperState |
| 93 | PonPortID uint32 |
| 94 | } |
| 95 | |
| 96 | type OnuDiscIndicationMessage struct { |
| 97 | OperState OperState |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 98 | Onu *Onu |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | type OnuIndicationMessage struct { |
| 102 | OperState OperState |
| 103 | PonPortID uint32 |
| 104 | OnuID uint32 |
| 105 | OnuSN *openolt.SerialNumber |
| 106 | } |
| 107 | |
| 108 | type OmciMessage struct { |
| 109 | OnuSN *openolt.SerialNumber |
| 110 | OnuID uint32 |
| 111 | omciMsg *openolt.OmciMsg |
| 112 | } |
| 113 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 114 | type OmciIndicationMessage struct { |
| 115 | OnuSN *openolt.SerialNumber |
| 116 | OnuID uint32 |
| 117 | OmciInd *openolt.OmciIndication |
| 118 | } |
| 119 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 120 | type OnuFlowUpdateMessage struct { |
| 121 | PonPortID uint32 |
| 122 | OnuID uint32 |
| 123 | Flow *openolt.Flow |
| 124 | } |
| 125 | |
| 126 | type PacketMessage struct { |
| 127 | PonPortID uint32 |
| 128 | OnuID uint32 |
| 129 | } |
| 130 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 131 | type OnuPacketMessage struct { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame^] | 132 | IntfId uint32 |
| 133 | OnuId uint32 |
| 134 | Packet gopacket.Packet |
| 135 | Type packetHandlers.PacketType |
| 136 | MacAddress net.HardwareAddr |
| 137 | GemPortId uint32 // this is used by BBR |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 140 | type OperState int |
| 141 | |
| 142 | const ( |
| 143 | UP OperState = iota |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 144 | DOWN // The device has been discovered, but not yet activated |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 145 | ) |
| 146 | |
| 147 | func (m OperState) String() string { |
| 148 | names := [...]string{ |
| 149 | "up", |
| 150 | "down", |
| 151 | } |
| 152 | return names[m] |
| 153 | } |