blob: 2faf8cd8e9ec786da6b575c44e2f300bb85d0a4c [file] [log] [blame]
Carmelo Cascone37f31ad2019-07-14 19:12:24 -07001/*
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
17package org.onosproject.drivers.stratum;
18
19import org.apache.commons.io.IOUtils;
20import org.onosproject.drivers.p4runtime.AbstractP4RuntimePipelineProgrammable;
21import org.onosproject.net.behaviour.PiPipelineProgrammable;
22import org.onosproject.net.pi.model.PiPipeconf;
23
24import java.io.IOException;
25import java.nio.ByteBuffer;
26import java.util.Optional;
27
28import 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 */
34public 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}