blob: b8d2f2786971869415ca2fa1fefe0d027f0b8618 [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 Cascone87892e22017-11-13 16:01:29 -080021import org.onosproject.net.behaviour.PiPipelineProgrammable;
Carmelo Cascone59f57de2017-07-11 19:55:09 -040022import org.onosproject.net.pi.model.PiPipeconf;
Carmelo Casconeca94bcf2017-10-27 14:16:59 -070023import org.onosproject.pipelines.basic.PipeconfLoader;
Carmelo Cascone59f57de2017-07-11 19:55:09 -040024
Carmelo Casconed61fdb32017-10-30 10:09:57 -070025import java.io.IOException;
26import java.nio.ByteBuffer;
Carmelo Cascone59f57de2017-07-11 19:55:09 -040027import java.util.Optional;
Carmelo Cascone59f57de2017-07-11 19:55:09 -040028
29import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON;
Carmelo Cascone59f57de2017-07-11 19:55:09 -040030
31/**
Carmelo Casconed61fdb32017-10-30 10:09:57 -070032 * Implementation of the PiPipelineProgrammable behavior for BMv2.
Carmelo Cascone59f57de2017-07-11 19:55:09 -040033 */
Carmelo Cascone87892e22017-11-13 16:01:29 -080034public class Bmv2PipelineProgrammable extends AbstractP4RuntimePipelineProgrammable
35 implements PiPipelineProgrammable {
Carmelo Cascone59f57de2017-07-11 19:55:09 -040036
37 @Override
Carmelo Casconed61fdb32017-10-30 10:09:57 -070038 public ByteBuffer createDeviceDataBuffer(PiPipeconf pipeconf) {
39 if (!pipeconf.extension(BMV2_JSON).isPresent()) {
40 log.warn("Missing extension {} in pipeconf {}", BMV2_JSON, pipeconf.id());
41 return null;
Carmelo Cascone59f57de2017-07-11 19:55:09 -040042 }
Carmelo Cascone59f57de2017-07-11 19:55:09 -040043 try {
Carmelo Casconed61fdb32017-10-30 10:09:57 -070044 return ByteBuffer.wrap(IOUtils.toByteArray(pipeconf.extension(BMV2_JSON).get()));
45 } catch (IOException e) {
46 log.warn("Unable to read {} from pipeconf {}", BMV2_JSON, pipeconf.id());
47 return null;
Carmelo Cascone59f57de2017-07-11 19:55:09 -040048 }
Carmelo Cascone59f57de2017-07-11 19:55:09 -040049 }
50
51 @Override
52 public Optional<PiPipeconf> getDefaultPipeconf() {
Carmelo Casconeca94bcf2017-10-27 14:16:59 -070053 return Optional.of(PipeconfLoader.BASIC_PIPECONF);
Carmelo Cascone59f57de2017-07-11 19:55:09 -040054 }
55}