Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [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 | |
| 17 | package org.onosproject.drivers.bmv2; |
| 18 | |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 19 | import org.apache.commons.io.IOUtils; |
| 20 | import org.onosproject.drivers.p4runtime.AbstractP4RuntimePipelineProgrammable; |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 21 | import org.onosproject.net.pi.model.PiPipeconf; |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 22 | import org.onosproject.pipelines.basic.PipeconfLoader; |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 23 | |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 24 | import java.io.IOException; |
| 25 | import java.nio.ByteBuffer; |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 26 | import java.util.Optional; |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 27 | |
| 28 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON; |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 29 | |
| 30 | /** |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 31 | * Implementation of the PiPipelineProgrammable behavior for BMv2. |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 32 | */ |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 33 | public class Bmv2PipelineProgrammable extends AbstractP4RuntimePipelineProgrammable { |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 34 | |
| 35 | @Override |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 36 | public ByteBuffer createDeviceDataBuffer(PiPipeconf pipeconf) { |
| 37 | if (!pipeconf.extension(BMV2_JSON).isPresent()) { |
| 38 | log.warn("Missing extension {} in pipeconf {}", BMV2_JSON, pipeconf.id()); |
| 39 | return null; |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 40 | } |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 41 | try { |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 42 | return ByteBuffer.wrap(IOUtils.toByteArray(pipeconf.extension(BMV2_JSON).get())); |
| 43 | } catch (IOException e) { |
| 44 | log.warn("Unable to read {} from pipeconf {}", BMV2_JSON, pipeconf.id()); |
| 45 | return null; |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 46 | } |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public Optional<PiPipeconf> getDefaultPipeconf() { |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 51 | return Optional.of(PipeconfLoader.BASIC_PIPECONF); |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 52 | } |
| 53 | } |