blob: 5fc42d57ced96cadc9b5284d0814d99b27ecbc0c [file] [log] [blame]
Daniele Moro8d630f12021-06-15 20:53:22 +02001/*
2 * Copyright 2021-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
17package org.onosproject.pipelines.fabric.impl.behaviour.upf;
18
19import io.grpc.ManagedChannel;
20import org.onosproject.net.DeviceId;
21import org.onosproject.net.device.DeviceAgentListener;
22import org.onosproject.net.pi.model.PiPipeconf;
23import org.onosproject.net.provider.ProviderId;
24import org.onosproject.p4runtime.api.P4RuntimeClient;
25import org.onosproject.p4runtime.api.P4RuntimeController;
26import org.onosproject.p4runtime.api.P4RuntimeEventListener;
27
28import static org.easymock.EasyMock.anyLong;
29import static org.easymock.EasyMock.anyObject;
30import static org.easymock.EasyMock.createMock;
31import static org.easymock.EasyMock.expect;
32import static org.easymock.EasyMock.replay;
33
34/**
35 * Currently only used to get mock clients that mock counter read requests.
36 */
37public class MockP4RuntimeController implements P4RuntimeController {
38
39 private final P4RuntimeClient mockP4rtClient;
40
41 /**
42 * Used to mock counter read requests.
43 *
44 * @param deviceId The ID of the device
45 * @param packets Packets counter value
46 * @param bytes Bytes counter value
47 * @param counterSize The size of the counter array
48 */
49 public MockP4RuntimeController(DeviceId deviceId, long packets, long bytes, int counterSize) {
50 mockP4rtClient = createMock(P4RuntimeClient.class);
51 expect(mockP4rtClient.read(anyLong(), anyObject(PiPipeconf.class)))
52 .andReturn(new MockReadRequest(deviceId, packets, bytes, counterSize))
53 .anyTimes();
54 replay(mockP4rtClient);
55 }
56
57 @Override
58 public P4RuntimeClient get(DeviceId deviceId) {
59 return mockP4rtClient;
60 }
61
62 @Override
63 public void addListener(P4RuntimeEventListener listener) {
64
65 }
66
67 @Override
68 public void removeListener(P4RuntimeEventListener listener) {
69
70 }
71
72 @Override
73 public boolean create(DeviceId deviceId, ManagedChannel channel) {
74 return false;
75 }
76
77 @Override
78 public void remove(DeviceId deviceId) {
79
80 }
81
82 @Override
83 public void addDeviceAgentListener(DeviceId deviceId, ProviderId providerId,
84 DeviceAgentListener listener) {
85
86 }
87
88 @Override
89 public void removeDeviceAgentListener(DeviceId deviceId,
90 ProviderId providerId) {
91
92 }
93}