Carmelo Cascone | 37f31ad | 2019-07-14 19:12:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 org.onosproject.drivers.stratum; |
| 18 | |
| 19 | import org.apache.commons.io.IOUtils; |
| 20 | import org.onosproject.drivers.p4runtime.AbstractP4RuntimePipelineProgrammable; |
| 21 | import org.onosproject.net.behaviour.PiPipelineProgrammable; |
| 22 | import org.onosproject.net.pi.model.PiPipeconf; |
| 23 | |
| 24 | import java.io.IOException; |
| 25 | import java.nio.ByteBuffer; |
| 26 | import java.util.Optional; |
| 27 | |
| 28 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.STRATUM_FPM_BIN; |
| 29 | |
| 30 | /** |
| 31 | * Implementation of the PiPipelineProgrammable behaviour for a Stratum |
| 32 | * Fixed-Pipeline Model (FPM) target. |
| 33 | */ |
| 34 | public class FpmPipelineProgrammable |
| 35 | extends AbstractP4RuntimePipelineProgrammable |
| 36 | implements PiPipelineProgrammable { |
| 37 | |
| 38 | @Override |
| 39 | public Optional<PiPipeconf> getDefaultPipeconf() { |
| 40 | return Optional.empty(); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public ByteBuffer createDeviceDataBuffer(PiPipeconf pipeconf) { |
| 45 | if (pipeconf.extension(STRATUM_FPM_BIN).isEmpty()) { |
| 46 | log.warn("Missing extension {} in pipeconf {}", |
| 47 | STRATUM_FPM_BIN, pipeconf.id()); |
| 48 | return null; |
| 49 | } |
| 50 | try { |
| 51 | return ByteBuffer.wrap(IOUtils.toByteArray( |
| 52 | pipeconf.extension(STRATUM_FPM_BIN).get())); |
| 53 | } catch (IOException e) { |
| 54 | log.warn("Unable to read {} from pipeconf {}", |
| 55 | STRATUM_FPM_BIN, pipeconf.id()); |
| 56 | return null; |
| 57 | } |
| 58 | } |
| 59 | } |