Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 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.test; |
| 18 | |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 19 | import com.google.common.collect.Lists; |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 20 | import io.grpc.ManagedChannelBuilder; |
| 21 | import io.grpc.netty.NettyChannelBuilder; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 22 | import org.junit.Before; |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 23 | import org.junit.Ignore; |
| 24 | import org.junit.Test; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 25 | import org.onlab.util.ImmutableByteSequence; |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 26 | import org.onosproject.grpc.ctl.GrpcControllerImpl; |
| 27 | import org.onosproject.net.DeviceId; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 28 | import org.onosproject.net.pi.model.PiActionId; |
| 29 | import org.onosproject.net.pi.model.PiActionParamId; |
| 30 | import org.onosproject.net.pi.model.PiActionProfileId; |
| 31 | import org.onosproject.net.pi.model.PiControlMetadataId; |
| 32 | import org.onosproject.net.pi.model.PiMatchFieldId; |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 33 | import org.onosproject.net.pi.model.PiPipeconf; |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 34 | import org.onosproject.net.pi.model.PiPipelineInterpreter; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 35 | import org.onosproject.net.pi.model.PiTableId; |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 36 | import org.onosproject.net.pi.runtime.PiAction; |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 37 | import org.onosproject.net.pi.runtime.PiActionGroup; |
| 38 | import org.onosproject.net.pi.runtime.PiActionGroupId; |
| 39 | import org.onosproject.net.pi.runtime.PiActionGroupMember; |
| 40 | import org.onosproject.net.pi.runtime.PiActionGroupMemberId; |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 41 | import org.onosproject.net.pi.runtime.PiActionParam; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 42 | import org.onosproject.net.pi.runtime.PiControlMetadata; |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 43 | import org.onosproject.net.pi.runtime.PiMatchKey; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 44 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 45 | import org.onosproject.net.pi.runtime.PiTableEntry; |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 46 | import org.onosproject.net.pi.runtime.PiTernaryFieldMatch; |
| 47 | import org.onosproject.p4runtime.api.P4RuntimeClient; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 48 | import org.onosproject.p4runtime.ctl.P4RuntimeClientImpl; |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 49 | import org.onosproject.p4runtime.ctl.P4RuntimeControllerImpl; |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 50 | import org.onosproject.pipelines.basic.PipeconfLoader; |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 51 | import org.slf4j.Logger; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 52 | import p4.P4RuntimeGrpc; |
| 53 | import p4.P4RuntimeOuterClass; |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 54 | |
| 55 | import java.net.URL; |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 56 | import java.util.Collection; |
| 57 | import java.util.concurrent.CompletableFuture; |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 58 | import java.util.concurrent.ExecutionException; |
| 59 | |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 60 | import static org.onlab.util.ImmutableByteSequence.copyFrom; |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 61 | import static org.onlab.util.ImmutableByteSequence.ofZeros; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 62 | import static org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT; |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 63 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON; |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 64 | import static org.slf4j.LoggerFactory.getLogger; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 65 | import static p4.P4RuntimeOuterClass.Update.Type.INSERT; |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Class used for quick testing of P4Runtime with real devices. To be removed before release. |
| 69 | */ |
| 70 | public class P4RuntimeTest { |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 71 | private static final Logger log = getLogger(P4RuntimeTest.class); |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 72 | |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 73 | private static final String GRPC_SERVER_ADDR = "192.168.56.102"; |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 74 | private static final int GRPC_SERVER_PORT = 55044; |
| 75 | |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 76 | private static final String DOT = "."; |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 77 | private static final String TABLE_0 = "table0"; |
| 78 | private static final String SET_EGRESS_PORT = "set_egress_port"; |
| 79 | private static final String PORT = "port"; |
| 80 | private static final String ETHERNET = "ethernet"; |
| 81 | private static final String DST_ADDR = "dstAddr"; |
| 82 | private static final String SRC_ADDR = "srcAddr"; |
| 83 | private static final String STANDARD_METADATA = "standard_metadata"; |
| 84 | private static final String INGRESS_PORT = "ingress_port"; |
| 85 | private static final String ETHER_TYPE = "etherType"; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 86 | |
Andrea Campanella | 0288c87 | 2017-08-07 18:32:51 +0200 | [diff] [blame] | 87 | |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 88 | private final URL p4InfoUrl = this.getClass().getResource("/p4c-out/bmv2/basic.p4info"); |
| 89 | private final URL jsonUrl = this.getClass().getResource("/p4c-out/bmv2/basic.json"); |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 90 | |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 91 | private final PiPipeconf bmv2DefaultPipeconf = PipeconfLoader.BASIC_PIPECONF; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 92 | private final P4RuntimeControllerImpl controller = new P4RuntimeControllerImpl(); |
| 93 | private final GrpcControllerImpl grpcController = new GrpcControllerImpl(); |
| 94 | private final DeviceId deviceId = DeviceId.deviceId("dummy:1"); |
| 95 | private final ManagedChannelBuilder channelBuilder = NettyChannelBuilder |
| 96 | .forAddress(GRPC_SERVER_ADDR, GRPC_SERVER_PORT) |
| 97 | .usePlaintext(true); |
| 98 | private P4RuntimeClientImpl client; |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 99 | |
Carmelo Cascone | 8a571af | 2018-04-06 23:17:04 -0700 | [diff] [blame] | 100 | private final ImmutableByteSequence ethAddr = copyFrom(1).fit(48); |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 101 | private final ImmutableByteSequence portValue = copyFrom((short) 1); |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 102 | private final PiMatchFieldId ethDstAddrFieldId = PiMatchFieldId.of(ETHERNET + DOT + DST_ADDR); |
| 103 | private final PiMatchFieldId ethSrcAddrFieldId = PiMatchFieldId.of(ETHERNET + DOT + SRC_ADDR); |
| 104 | private final PiMatchFieldId inPortFieldId = PiMatchFieldId.of(STANDARD_METADATA + DOT + INGRESS_PORT); |
| 105 | private final PiMatchFieldId ethTypeFieldId = PiMatchFieldId.of(ETHERNET + DOT + ETHER_TYPE); |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 106 | private final PiActionParamId portParamId = PiActionParamId.of(PORT); |
| 107 | private final PiActionId outActionId = PiActionId.of(SET_EGRESS_PORT); |
| 108 | private final PiTableId tableId = PiTableId.of(TABLE_0); |
| 109 | |
| 110 | private final PiTableEntry piTableEntry = PiTableEntry |
| 111 | .builder() |
| 112 | .forTable(tableId) |
| 113 | .withMatchKey(PiMatchKey.builder() |
| 114 | .addFieldMatch(new PiTernaryFieldMatch(ethDstAddrFieldId, ethAddr, ofZeros(6))) |
| 115 | .addFieldMatch(new PiTernaryFieldMatch(ethSrcAddrFieldId, ethAddr, ofZeros(6))) |
| 116 | .addFieldMatch(new PiTernaryFieldMatch(inPortFieldId, portValue, ofZeros(2))) |
| 117 | .addFieldMatch(new PiTernaryFieldMatch(ethTypeFieldId, portValue, ofZeros(2))) |
| 118 | .build()) |
| 119 | .withAction(PiAction |
| 120 | .builder() |
| 121 | .withId(outActionId) |
| 122 | .withParameter(new PiActionParam(portParamId, portValue)) |
| 123 | .build()) |
| 124 | .withPriority(1) |
| 125 | .withCookie(2) |
| 126 | .build(); |
| 127 | |
| 128 | public P4RuntimeTest() throws ImmutableByteSequence.ByteSequenceTrimException { |
| 129 | } |
| 130 | |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 131 | @Before |
| 132 | public void setUp() throws Exception { |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 133 | controller.grpcController = grpcController; |
| 134 | GrpcControllerImpl.enableMessageLog = true; |
| 135 | grpcController.activate(); |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 136 | } |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 137 | |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 138 | private void createClient() |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 139 | throws ExecutionException, InterruptedException, PiPipelineInterpreter.PiInterpreterException, |
| 140 | IllegalAccessException, InstantiationException { |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 141 | |
| 142 | assert (controller.createClient(deviceId, 1, channelBuilder)); |
| 143 | |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 144 | client = (P4RuntimeClientImpl) controller.getClient(deviceId); |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | private void setPipelineConfig(PiPipeconf pipeconf, PiPipeconf.ExtensionType extensionType) |
| 148 | throws ExecutionException, InterruptedException, PiPipelineInterpreter.PiInterpreterException, |
| 149 | IllegalAccessException, InstantiationException { |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 150 | // FIXME: setPipelineConfig now takes a byte buffer, not extension type |
| 151 | // assert (client.setPipelineConfig(pipeconf, extensionType).get()); |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 152 | assert (client.initStreamChannel().get()); |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 153 | } |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 154 | |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 155 | private void testActionProfile(int actionProfileId) { |
| 156 | |
| 157 | P4RuntimeGrpc.P4RuntimeBlockingStub stub = client.blockingStub(); |
| 158 | |
| 159 | P4RuntimeOuterClass.ActionProfileMember profileMemberMsg = P4RuntimeOuterClass.ActionProfileMember.newBuilder() |
| 160 | .setActionProfileId(actionProfileId) |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 161 | .setMemberId(1) |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 162 | .setAction(P4RuntimeOuterClass.Action.newBuilder() |
| 163 | .setActionId(16793508) |
| 164 | .build()) |
| 165 | .build(); |
| 166 | |
| 167 | P4RuntimeOuterClass.ActionProfileGroup groupMsg = P4RuntimeOuterClass.ActionProfileGroup.newBuilder() |
| 168 | .setActionProfileId(actionProfileId) |
| 169 | .setGroupId(1) |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 170 | .addMembers(P4RuntimeOuterClass.ActionProfileGroup.Member.newBuilder() |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 171 | .setMemberId(1) |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 172 | .setWeight(1) |
| 173 | .build()) |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 174 | .setMaxSize(3) |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 175 | .build(); |
| 176 | |
| 177 | P4RuntimeOuterClass.WriteRequest writeRequest = P4RuntimeOuterClass.WriteRequest.newBuilder() |
| 178 | .setDeviceId(client.p4DeviceId()) |
| 179 | .addUpdates(P4RuntimeOuterClass.Update.newBuilder() |
| 180 | .setType(INSERT) |
| 181 | .setEntity(P4RuntimeOuterClass.Entity.newBuilder() |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 182 | .setActionProfileGroup(groupMsg) |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 183 | .build()) |
| 184 | .build()) |
| 185 | .addUpdates(P4RuntimeOuterClass.Update.newBuilder() |
| 186 | .setType(INSERT) |
| 187 | .setEntity(P4RuntimeOuterClass.Entity.newBuilder() |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 188 | .setActionProfileMember(profileMemberMsg) |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 189 | .build()) |
| 190 | .build()) |
| 191 | .build(); |
| 192 | |
| 193 | stub.write(writeRequest); |
| 194 | } |
| 195 | |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 196 | private void testPacketOut() throws IllegalAccessException, InstantiationException, ExecutionException, |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 197 | InterruptedException, ImmutableByteSequence.ByteSequenceTrimException { |
| 198 | |
| 199 | PiPacketOperation packetOperation = PiPacketOperation.builder() |
Carmelo Cascone | 8a571af | 2018-04-06 23:17:04 -0700 | [diff] [blame] | 200 | .withData(copyFrom(1).fit(48 + 48 + 16)) |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 201 | .withType(PACKET_OUT) |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 202 | .withMetadata(PiControlMetadata.builder() |
| 203 | .withId(PiControlMetadataId.of("egress_port")) |
Carmelo Cascone | 8a571af | 2018-04-06 23:17:04 -0700 | [diff] [blame] | 204 | .withValue(copyFrom(255).fit(9)) |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 205 | .build()) |
| 206 | .build(); |
| 207 | |
| 208 | assert (client.packetOut(packetOperation, bmv2DefaultPipeconf).get()); |
Carmelo Cascone | a966c34 | 2017-07-30 01:56:30 -0400 | [diff] [blame] | 209 | |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 210 | Thread.sleep(5000); |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | private void testDumpTable(String tableName, PiPipeconf pipeconf) throws ExecutionException, InterruptedException { |
| 214 | assert (client.dumpTable(PiTableId.of(tableName), pipeconf).get().size() == 0); |
| 215 | } |
| 216 | |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 217 | private void testAddEntry(PiPipeconf pipeconf) throws ExecutionException, InterruptedException { |
| 218 | assert (client.writeTableEntries(Lists.newArrayList(piTableEntry), P4RuntimeClient.WriteOperationType.INSERT, |
| 219 | pipeconf).get()); |
| 220 | } |
| 221 | |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 222 | @Test |
| 223 | @Ignore |
| 224 | public void testBmv2() throws Exception { |
| 225 | |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 226 | createClient(); |
| 227 | setPipelineConfig(bmv2DefaultPipeconf, BMV2_JSON); |
| 228 | testPacketOut(); |
| 229 | |
| 230 | // testPacketOut(); |
| 231 | |
| 232 | // testActionProfile(285261835); |
| 233 | } |
| 234 | |
| 235 | @Test |
| 236 | @Ignore |
| 237 | public void testBmv2AddEntry() throws Exception { |
| 238 | createClient(); |
| 239 | testAddEntry(bmv2DefaultPipeconf); |
| 240 | testDumpTable(TABLE_0, bmv2DefaultPipeconf); |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | @Test |
| 244 | @Ignore |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 245 | public void testBmv2ActionProfile() throws Exception { |
| 246 | createClient(); |
| 247 | setPipelineConfig(bmv2DefaultPipeconf, BMV2_JSON); |
| 248 | PiActionProfileId actionProfileId = PiActionProfileId.of("ecmp_selector"); |
| 249 | PiActionGroupId groupId = PiActionGroupId.of(1); |
| 250 | |
| 251 | Collection<PiActionGroupMember> members = Lists.newArrayList(); |
| 252 | |
| 253 | for (int port = 1; port <= 4; port++) { |
| 254 | PiAction memberAction = PiAction.builder() |
| 255 | .withId(PiActionId.of(SET_EGRESS_PORT)) |
| 256 | .withParameter(new PiActionParam(PiActionParamId.of(PORT), |
| 257 | ImmutableByteSequence.copyFrom((short) port))) |
| 258 | .build(); |
| 259 | PiActionGroupMemberId memberId = PiActionGroupMemberId.of(port); |
| 260 | PiActionGroupMember member = PiActionGroupMember.builder() |
| 261 | .withId(memberId) |
| 262 | .withAction(memberAction) |
| 263 | .withWeight(port) |
| 264 | .build(); |
| 265 | members.add(member); |
| 266 | } |
| 267 | PiActionGroup actionGroup = PiActionGroup.builder() |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 268 | .withActionProfileId(actionProfileId) |
| 269 | .withId(groupId) |
| 270 | .addMembers(members) |
| 271 | .build(); |
Carmelo Cascone | 87b9b39 | 2017-10-02 18:33:20 +0200 | [diff] [blame] | 272 | CompletableFuture<Boolean> success = client.writeActionGroupMembers(actionGroup, |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 273 | P4RuntimeClient.WriteOperationType.INSERT, |
| 274 | bmv2DefaultPipeconf); |
| 275 | assert (success.get()); |
| 276 | |
| 277 | success = client.writeActionGroup(actionGroup, P4RuntimeClient.WriteOperationType.INSERT, bmv2DefaultPipeconf); |
| 278 | assert (success.get()); |
| 279 | |
| 280 | CompletableFuture<Collection<PiActionGroup>> piGroups = client.dumpGroups(actionProfileId, bmv2DefaultPipeconf); |
| 281 | |
| 282 | log.info("Number of groups: {}", piGroups.get().size()); |
| 283 | piGroups.get().forEach(piGroup -> { |
| 284 | log.info("Group {}", piGroup); |
| 285 | log.info("------"); |
| 286 | piGroup.members().forEach(piMem -> { |
| 287 | log.info(" {}", piMem); |
| 288 | }); |
| 289 | }); |
| 290 | } |
| 291 | |
| 292 | @Test |
| 293 | @Ignore |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 294 | public void testTofino() throws Exception { |
Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame] | 295 | createClient(); |
| 296 | setPipelineConfig(bmv2DefaultPipeconf, null); |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | // OLD STUFF |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 300 | // log.info("++++++++++++++++++++++++++++"); |
| 301 | // |
| 302 | // PiPipelineInterpreter interpreter = (PiPipelineInterpreter) defaultPipeconf |
| 303 | // .implementation(PiPipelineInterpreter.class) |
| 304 | // .orElse(null) |
| 305 | // .newInstance(); |
| 306 | // |
| 307 | // TrafficTreatment t = DefaultTrafficTreatment.builder() |
| 308 | // .setOutput(PortNumber.portNumber(830L)).build(); |
| 309 | // byte[] payload = new byte[1000]; |
| 310 | //// payload[0] = 1; |
| 311 | // Arrays.fill( payload, (byte) 1 ); |
| 312 | // |
| 313 | // OutboundPacket packet = new DefaultOutboundPacket( |
| 314 | // deviceId, t, ByteBuffer.wrap(payload)); |
| 315 | // |
| 316 | // |
| 317 | // Collection<PiPacketOperation> operations = interpreter.mapOutboundPacket(packet,defaultPipeconf); |
| 318 | // log.info("{}", operations); |
| 319 | // operations.forEach(piPacketOperation -> { |
| 320 | // try { |
| 321 | // client.packetOut(piPacketOperation, defaultPipeconf).get(); |
| 322 | // } catch (InterruptedException | ExecutionException e) { |
| 323 | // log.error("{}",e); |
| 324 | // } |
| 325 | // }); |
| 326 | |
| 327 | // assert(client.dumpTable(PiTableId.of(TABLE_0), defaultPipeconf).get().size() == 0); |
| 328 | |
| 329 | // assert(client.writeTableEntries(Lists.newArrayList(piTableEntry), INSERT, defaultPipeconf).get()); |
| 330 | |
| 331 | // assert(client.dumpTable(PiTableId.of(TABLE_0), defaultPipeconf).get().size() == 1); |
Carmelo Cascone | c8e8498 | 2017-07-26 15:34:42 -0400 | [diff] [blame] | 332 | } |