Carmelo Cascone | 98dfdb7 | 2017-07-14 12:01:37 -0400 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.p4runtime.ctl; |
| 18 | |
| 19 | import com.google.protobuf.ExtensionRegistry; |
| 20 | import com.google.protobuf.TextFormat; |
| 21 | import org.junit.Test; |
| 22 | import p4.config.P4InfoOuterClass; |
| 23 | |
| 24 | import java.io.InputStream; |
| 25 | import java.io.InputStreamReader; |
| 26 | |
| 27 | import static org.hamcrest.MatcherAssert.assertThat; |
| 28 | import static org.hamcrest.Matchers.is; |
| 29 | |
| 30 | public 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 | } |