blob: eb773e3b1ec7710f49cbc08c65269e9d209964bf [file] [log] [blame]
Carmelo Cascone360c9e52018-01-31 16:00:48 -08001/*
2 * Copyright 2018-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.cavium.pro;
18
Carmelo Casconece1bf712018-02-01 13:38:30 -080019import org.onosproject.drivers.bmv2.Bmv2PipelineProgrammable;
Carmelo Cascone360c9e52018-01-31 16:00:48 -080020import org.onosproject.net.behaviour.PiPipelineProgrammable;
21import org.onosproject.net.pi.model.PiPipeconf;
22import org.onosproject.net.pi.model.PiPipeconfId;
23import org.onosproject.net.pi.service.PiPipeconfService;
24
25import java.nio.ByteBuffer;
26import java.util.Optional;
27
28import static com.google.common.base.Preconditions.checkArgument;
29import static java.lang.String.format;
30
31/**
32 * Implementation of the PiPipelineProgrammable behaviour for a Xpliant-based
33 * switch.
34 */
Carmelo Casconece1bf712018-02-01 13:38:30 -080035public class XpliantProPipelineProgrammable extends Bmv2PipelineProgrammable
Carmelo Cascone360c9e52018-01-31 16:00:48 -080036 implements PiPipelineProgrammable {
37
38 private static final PiPipeconfId FABRIC_PIPECONF_ID =
39 new PiPipeconfId("org.onosproject.pipelines.fabric");
40
41 @Override
42 public ByteBuffer createDeviceDataBuffer(PiPipeconf pipeconf) {
43 checkArgument(pipeconf.id().equals(FABRIC_PIPECONF_ID),
44 format("Cannot program XPliant device with a pipeconf " +
45 "other than '%s' (found '%s')",
46 FABRIC_PIPECONF_ID, pipeconf.id()));
Carmelo Casconece1bf712018-02-01 13:38:30 -080047 return super.createDeviceDataBuffer(pipeconf);
Carmelo Cascone360c9e52018-01-31 16:00:48 -080048 }
49
50 @Override
51 public Optional<PiPipeconf> getDefaultPipeconf() {
52 return handler().get(PiPipeconfService.class)
53 .getPipeconf(FABRIC_PIPECONF_ID);
54 }
55}