Carmelo Cascone | 9db4d5c | 2019-04-16 17:36:33 -0700 | [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 | |
| 19 | import org.onosproject.net.pi.model.PiPipeconf; |
| 20 | import org.onosproject.net.pi.runtime.PiCloneSessionEntry; |
| 21 | import org.onosproject.net.pi.runtime.PiCloneSessionEntryHandle; |
| 22 | import org.onosproject.p4runtime.ctl.utils.P4InfoBrowser; |
| 23 | import p4.v1.P4RuntimeOuterClass; |
| 24 | |
| 25 | import static org.onosproject.p4runtime.ctl.codec.Codecs.CODECS; |
| 26 | |
| 27 | /** |
| 28 | * Codec for P4Runtime CloneSessionEntry. |
| 29 | */ |
| 30 | public final class CloneSessionEntryCodec |
| 31 | extends AbstractEntityCodec<PiCloneSessionEntry, PiCloneSessionEntryHandle, |
| 32 | P4RuntimeOuterClass.CloneSessionEntry, Object> { |
| 33 | |
| 34 | @Override |
| 35 | protected P4RuntimeOuterClass.CloneSessionEntry encode( |
| 36 | PiCloneSessionEntry piEntity, Object ignored, |
| 37 | PiPipeconf pipeconf, P4InfoBrowser browser) throws CodecException { |
| 38 | return P4RuntimeOuterClass.CloneSessionEntry.newBuilder() |
| 39 | .setSessionId(piEntity.sessionId()) |
| 40 | .addAllReplicas( |
| 41 | CODECS.preReplica().encodeAll( |
| 42 | piEntity.replicas(), null, pipeconf)) |
| 43 | .setClassOfService(piEntity.classOfService()) |
| 44 | .setPacketLengthBytes(piEntity.maxPacketLengthBytes()) |
| 45 | .build(); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | protected P4RuntimeOuterClass.CloneSessionEntry encodeKey( |
| 50 | PiCloneSessionEntryHandle handle, Object metadata, |
| 51 | PiPipeconf pipeconf, P4InfoBrowser browser) { |
| 52 | return P4RuntimeOuterClass.CloneSessionEntry.newBuilder() |
| 53 | .setSessionId(handle.sessionId()).build(); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | protected P4RuntimeOuterClass.CloneSessionEntry encodeKey( |
| 58 | PiCloneSessionEntry piEntity, Object metadata, |
| 59 | PiPipeconf pipeconf, P4InfoBrowser browser) { |
| 60 | return P4RuntimeOuterClass.CloneSessionEntry.newBuilder() |
| 61 | .setSessionId(piEntity.sessionId()).build(); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | protected PiCloneSessionEntry decode( |
| 66 | P4RuntimeOuterClass.CloneSessionEntry message, Object ignored, |
| 67 | PiPipeconf pipeconf, P4InfoBrowser browser) throws CodecException { |
| 68 | return PiCloneSessionEntry.builder() |
| 69 | .withSessionId(message.getSessionId()) |
| 70 | .addReplicas( |
| 71 | CODECS.preReplica().decodeAll( |
| 72 | message.getReplicasList(), null, pipeconf)) |
| 73 | .withClassOfService(message.getClassOfService()) |
| 74 | .withMaxPacketLengthBytes(message.getPacketLengthBytes()) |
| 75 | .build(); |
| 76 | } |
| 77 | } |