blob: c13ab77aaf8460d3536ec91032d3613e5698840f [file] [log] [blame]
Carmelo Casconee8691d92018-04-19 09:28:01 +09001/*
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.mellanox;
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 Spectrum-based
33 * switch with P4Runtime support.
34 */
35public class SpectrumPipelineProgrammable
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 Spectrum device with a pipeconf " +
46 "other than '%s' (found '%s')",
47 FABRIC_PIPECONF_ID, pipeconf.id()));
48 // Dummy value.
49 // We assume switch to be already configured with fabric.p4 profile.
50 return ByteBuffer.allocate(1).put((byte) 1);
51 }
52
53 @Override
54 public Optional<PiPipeconf> getDefaultPipeconf() {
55 return handler().get(PiPipeconfService.class)
56 .getPipeconf(FABRIC_PIPECONF_ID);
57 }
58}