blob: a6800a8cafc062af8f1898dc48580cbc0123b9cf [file] [log] [blame]
Carmelo Cascone6e854042017-09-11 21:37:53 +02001/*
2 * Copyright 2017-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.pi.demo.app.ecmp;
18
19import org.onosproject.bmv2.model.Bmv2PipelineModelParser;
20import org.onosproject.driver.pipeline.DefaultSingleTablePipeline;
21import org.onosproject.drivers.p4runtime.DefaultP4PortStatisticsDiscovery;
22import org.onosproject.net.behaviour.Pipeliner;
23import org.onosproject.net.device.PortStatisticsDiscovery;
24import org.onosproject.net.pi.model.DefaultPiPipeconf;
25import org.onosproject.net.pi.model.PiPipeconf;
26import org.onosproject.net.pi.model.PiPipeconfId;
27import org.onosproject.net.pi.model.PiPipelineInterpreter;
28
29import java.net.URL;
30import java.util.Collection;
31import java.util.Collections;
32
33import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON;
34import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.P4_INFO_TEXT;
35
36final class EcmpPipeconfFactory {
37
38 private static final String BMV2_PIPECONF_ID = "pi-demo-ecmp";
39 private static final URL BMV2_P4INFO_URL = EcmpFabricApp.class.getResource("/ecmp.p4info");
40 private static final URL BMV2_JSON_URL = EcmpFabricApp.class.getResource("/ecmp.json");
41
42 private static final PiPipeconf BMV2_PIPECONF = buildBmv2Pipeconf();
43
44 private EcmpPipeconfFactory() {
45 // Hides constructor.
46 }
47
48 static Collection<PiPipeconf> getAll() {
49 return Collections.singleton(BMV2_PIPECONF);
50 }
51
52 private static PiPipeconf buildBmv2Pipeconf() {
53 return DefaultPiPipeconf.builder()
54 .withId(new PiPipeconfId(BMV2_PIPECONF_ID))
55 .withPipelineModel(Bmv2PipelineModelParser.parse(BMV2_JSON_URL))
56 .addBehaviour(PiPipelineInterpreter.class, EcmpInterpreter.class)
57 .addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class)
58 .addBehaviour(PortStatisticsDiscovery.class, DefaultP4PortStatisticsDiscovery.class)
59 .addExtension(P4_INFO_TEXT, BMV2_P4INFO_URL)
60 .addExtension(BMV2_JSON, BMV2_JSON_URL)
61 .build();
62 }
63}