Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-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 | |
| 17 | package org.onosproject.p4runtime.ctl.codec; |
| 18 | |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 19 | import org.onosproject.net.pi.model.PiPipeconf; |
| 20 | import org.onosproject.net.pi.runtime.PiMulticastGroupEntry; |
| 21 | import org.onosproject.net.pi.runtime.PiMulticastGroupEntryHandle; |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 22 | import org.onosproject.p4runtime.ctl.utils.P4InfoBrowser; |
| 23 | import p4.v1.P4RuntimeOuterClass; |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 24 | |
Carmelo Cascone | 9db4d5c | 2019-04-16 17:36:33 -0700 | [diff] [blame] | 25 | import static org.onosproject.p4runtime.ctl.codec.Codecs.CODECS; |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Codec for P4Runtime MulticastGroupEntry. |
| 29 | */ |
| 30 | public final class MulticastGroupEntryCodec |
| 31 | extends AbstractEntityCodec<PiMulticastGroupEntry, PiMulticastGroupEntryHandle, |
| 32 | P4RuntimeOuterClass.MulticastGroupEntry, Object> { |
| 33 | |
| 34 | @Override |
| 35 | protected P4RuntimeOuterClass.MulticastGroupEntry encode( |
| 36 | PiMulticastGroupEntry piEntity, Object ignored, |
| 37 | PiPipeconf pipeconf, P4InfoBrowser browser) throws CodecException { |
Carmelo Cascone | 9db4d5c | 2019-04-16 17:36:33 -0700 | [diff] [blame] | 38 | return P4RuntimeOuterClass.MulticastGroupEntry.newBuilder() |
| 39 | .setMulticastGroupId(piEntity.groupId()) |
| 40 | .addAllReplicas( |
| 41 | CODECS.preReplica().encodeAll( |
| 42 | piEntity.replicas(), null, pipeconf)) |
| 43 | .build(); |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | @Override |
| 47 | protected P4RuntimeOuterClass.MulticastGroupEntry encodeKey( |
| 48 | PiMulticastGroupEntryHandle handle, Object metadata, |
| 49 | PiPipeconf pipeconf, P4InfoBrowser browser) { |
| 50 | return P4RuntimeOuterClass.MulticastGroupEntry.newBuilder() |
| 51 | .setMulticastGroupId(handle.groupId()).build(); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | protected P4RuntimeOuterClass.MulticastGroupEntry encodeKey( |
| 56 | PiMulticastGroupEntry piEntity, Object metadata, |
| 57 | PiPipeconf pipeconf, P4InfoBrowser browser) { |
| 58 | return P4RuntimeOuterClass.MulticastGroupEntry.newBuilder() |
| 59 | .setMulticastGroupId(piEntity.groupId()).build(); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | protected PiMulticastGroupEntry decode( |
| 64 | P4RuntimeOuterClass.MulticastGroupEntry message, Object ignored, |
Carmelo Cascone | 9db4d5c | 2019-04-16 17:36:33 -0700 | [diff] [blame] | 65 | PiPipeconf pipeconf, P4InfoBrowser browser) throws CodecException { |
| 66 | return PiMulticastGroupEntry.builder() |
| 67 | .withGroupId(message.getMulticastGroupId()) |
| 68 | .addReplicas( |
| 69 | CODECS.preReplica().decodeAll( |
| 70 | message.getReplicasList(), null, pipeconf)) |
| 71 | .build(); |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 72 | } |
| 73 | } |