blob: bf7061f851f4a96b715fd2f0ffc4232757b8937c [file] [log] [blame]
Carmelo Cascone59f57de2017-07-11 19:55:09 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Carmelo Cascone59f57de2017-07-11 19:55:09 -04003 *
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.bmv2;
18
Carmelo Casconed61fdb32017-10-30 10:09:57 -070019import org.apache.commons.io.IOUtils;
20import org.onosproject.drivers.p4runtime.AbstractP4RuntimePipelineProgrammable;
Carmelo Cascone59f57de2017-07-11 19:55:09 -040021import org.onosproject.net.pi.model.PiPipeconf;
Carmelo Casconeca94bcf2017-10-27 14:16:59 -070022import org.onosproject.pipelines.basic.PipeconfLoader;
Carmelo Cascone59f57de2017-07-11 19:55:09 -040023
Carmelo Casconed61fdb32017-10-30 10:09:57 -070024import java.io.IOException;
25import java.nio.ByteBuffer;
Carmelo Cascone59f57de2017-07-11 19:55:09 -040026import java.util.Optional;
Carmelo Cascone59f57de2017-07-11 19:55:09 -040027
28import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON;
Carmelo Cascone59f57de2017-07-11 19:55:09 -040029
30/**
Carmelo Casconed61fdb32017-10-30 10:09:57 -070031 * Implementation of the PiPipelineProgrammable behavior for BMv2.
Carmelo Cascone59f57de2017-07-11 19:55:09 -040032 */
Carmelo Casconed61fdb32017-10-30 10:09:57 -070033public class Bmv2PipelineProgrammable extends AbstractP4RuntimePipelineProgrammable {
Carmelo Cascone59f57de2017-07-11 19:55:09 -040034
35 @Override
Carmelo Casconed61fdb32017-10-30 10:09:57 -070036 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 Cascone59f57de2017-07-11 19:55:09 -040040 }
Carmelo Cascone59f57de2017-07-11 19:55:09 -040041 try {
Carmelo Casconed61fdb32017-10-30 10:09:57 -070042 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 Cascone59f57de2017-07-11 19:55:09 -040046 }
Carmelo Cascone59f57de2017-07-11 19:55:09 -040047 }
48
49 @Override
50 public Optional<PiPipeconf> getDefaultPipeconf() {
Carmelo Casconeca94bcf2017-10-27 14:16:59 -070051 return Optional.of(PipeconfLoader.BASIC_PIPECONF);
Carmelo Cascone59f57de2017-07-11 19:55:09 -040052 }
53}