Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 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 | |
Andrea Campanella | 0288c87 | 2017-08-07 18:32:51 +0200 | [diff] [blame] | 17 | package org.onosproject.drivers.p4runtime; |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 18 | |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 19 | import org.onosproject.net.packet.OutboundPacket; |
| 20 | import org.onosproject.net.packet.PacketProgrammable; |
Frank Wang | c672c98 | 2017-07-18 16:09:28 +0800 | [diff] [blame] | 21 | import org.onosproject.net.pi.model.PiPipelineInterpreter; |
| 22 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
Frank Wang | c672c98 | 2017-07-18 16:09:28 +0800 | [diff] [blame] | 23 | |
Andrea Campanella | fc1d34c | 2017-07-18 17:01:41 +0200 | [diff] [blame] | 24 | import java.util.Collection; |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 25 | |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 26 | /** |
Carmelo Cascone | e3a7c74 | 2017-09-01 01:25:52 +0200 | [diff] [blame] | 27 | * Implementation of PacketProgrammable behaviour for P4Runtime. |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 28 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 29 | public class P4RuntimePacketProgrammable |
| 30 | extends AbstractP4RuntimeHandlerBehaviour |
| 31 | implements PacketProgrammable { |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 32 | |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 33 | @Override |
| 34 | public void emit(OutboundPacket packet) { |
Frank Wang | c672c98 | 2017-07-18 16:09:28 +0800 | [diff] [blame] | 35 | |
Carmelo Cascone | e3a7c74 | 2017-09-01 01:25:52 +0200 | [diff] [blame] | 36 | if (!this.setupBehaviour()) { |
Frank Wang | c672c98 | 2017-07-18 16:09:28 +0800 | [diff] [blame] | 37 | return; |
| 38 | } |
| 39 | |
Carmelo Cascone | 158b8c4 | 2018-07-04 19:42:37 +0200 | [diff] [blame] | 40 | final PiPipelineInterpreter interpreter = getInterpreter(); |
Ray Milkey | 74e5913 | 2018-01-17 15:24:52 -0800 | [diff] [blame] | 41 | if (interpreter == null) { |
Carmelo Cascone | 158b8c4 | 2018-07-04 19:42:37 +0200 | [diff] [blame] | 42 | // Error logged by getInterpreter(). |
Frank Wang | c672c98 | 2017-07-18 16:09:28 +0800 | [diff] [blame] | 43 | return; |
| 44 | } |
| 45 | |
| 46 | try { |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 47 | Collection<PiPacketOperation> operations = interpreter.mapOutboundPacket(packet); |
Andrea Campanella | fc1d34c | 2017-07-18 17:01:41 +0200 | [diff] [blame] | 48 | operations.forEach(piPacketOperation -> { |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 49 | log.debug("Doing PiPacketOperation {}", piPacketOperation); |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 50 | getFutureWithDeadline( |
| 51 | client.packetOut(piPacketOperation, pipeconf), |
| 52 | "sending packet-out", false); |
Andrea Campanella | fc1d34c | 2017-07-18 17:01:41 +0200 | [diff] [blame] | 53 | }); |
Frank Wang | c672c98 | 2017-07-18 16:09:28 +0800 | [diff] [blame] | 54 | } catch (PiPipelineInterpreter.PiInterpreterException e) { |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 55 | log.error("Unable to translate outbound packet for {} with pipeconf {}: {}", |
| 56 | deviceId, pipeconf.id(), e.getMessage()); |
Frank Wang | c672c98 | 2017-07-18 16:09:28 +0800 | [diff] [blame] | 57 | } |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 58 | } |
| 59 | } |