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