bmv2
Designing your own switch target with bmv2
packet_handler.h
1 /* Copyright 2013-present Barefoot Networks, Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef BM_BM_SIM_PACKET_HANDLER_H_
17 #define BM_BM_SIM_PACKET_HANDLER_H_
18 
19 #include <functional>
20 
21 namespace bm {
22 
23 class PacketDispatcherIface {
24  public:
25  using PacketHandler = std::function<void(int port_num, const char *buffer,
26  int len, void* cookie)>;
27  enum class ReturnCode {
28  SUCCESS,
29  UNSUPPORTED,
30  ERROR
31  };
32 
33  virtual ReturnCode set_packet_handler(const PacketHandler &handler,
34  void* cookie) = 0;
35 };
36 
37 class PacketReceiverIface {
38  public:
39  virtual void send_packet(int port_num, const char* buffer, int len) = 0;
40 };
41 
42 } // namespace bm
43 
44 #endif // BM_BM_SIM_PACKET_HANDLER_H_