blob: 5f21751e8ce2b9f823d19bed7854821365be390a [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
19import org.onosproject.drivers.p4runtime.AbstractP4RuntimePipelineProgrammable;
20import 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 */
35public class XpliantProPipelineProgrammable
36 extends AbstractP4RuntimePipelineProgrammable
37 implements PiPipelineProgrammable {
38
39 private static final PiPipeconfId FABRIC_PIPECONF_ID =
40 new PiPipeconfId("org.onosproject.pipelines.fabric");
41
42 @Override
43 public ByteBuffer createDeviceDataBuffer(PiPipeconf pipeconf) {
44 checkArgument(pipeconf.id().equals(FABRIC_PIPECONF_ID),
45 format("Cannot program XPliant device with a pipeconf " +
46 "other than '%s' (found '%s')",
47 FABRIC_PIPECONF_ID, pipeconf.id()));
48 // [MWC-2018] Dummy value. The chip is already configured with fabric.p4
49 return ByteBuffer.allocate(1).put((byte) 1);
50 }
51
52 @Override
53 public Optional<PiPipeconf> getDefaultPipeconf() {
54 return handler().get(PiPipeconfService.class)
55 .getPipeconf(FABRIC_PIPECONF_ID);
56 }
57}