blob: 17263e4331714adfd00b8376ccf49d03bdb0ef8f [file] [log] [blame]
Carmelo Cascone98dfdb72017-07-14 12:01:37 -04001/*
2 * Copyright 2017-present Open Networking Laboratory
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.p4runtime.ctl;
18
19import com.google.protobuf.ExtensionRegistry;
20import com.google.protobuf.TextFormat;
21import org.junit.Test;
22import p4.config.P4InfoOuterClass;
23
24import java.io.InputStream;
25import java.io.InputStreamReader;
26
27import static org.hamcrest.MatcherAssert.assertThat;
28import static org.hamcrest.Matchers.is;
29
30public class TestP4Info {
31
32 private InputStream p4InfoStream = this.getClass().getResourceAsStream("/default.p4info");
33
34 @Test
35 public void testP4InfoBrowser() throws Exception {
36
37 InputStreamReader input = new InputStreamReader(p4InfoStream);
38 ExtensionRegistry extensionRegistry = ExtensionRegistry.getEmptyRegistry();
39 P4InfoOuterClass.P4Info.Builder builder = P4InfoOuterClass.P4Info.newBuilder();
40
41 builder.clear();
42 TextFormat.getParser().merge(input, extensionRegistry, builder);
43 P4InfoOuterClass.P4Info p4Info = builder.build();
44
45 P4InfoBrowser browser = new P4InfoBrowser(p4Info);
46
47 assertThat(browser.tables().hasName("table0"), is(true));
48 assertThat(browser.actions().hasName("set_egress_port"), is(true));
49
50 int tableId = browser.tables().getByName("table0").getPreamble().getId();
51 int actionId = browser.actions().getByName("set_egress_port").getPreamble().getId();
52
53 assertThat(browser.matchFields(tableId).hasName("standard_metadata.ingress_port"), is(true));
54 assertThat(browser.actionParams(actionId).hasName("port"), is(true));
55
56 // TODO: improve, assert browsing of other entities (counters, meters, etc.)
57 }
58}