blob: 73a8b6543e1c3048d2bfd2b15db39806d491a66e [file] [log] [blame]
pier6a2052b2019-06-28 22:17:31 +02001/*
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
17package org.onosproject.segmentrouting;
18
19import com.google.common.collect.Maps;
20import org.apache.commons.lang3.tuple.Pair;
21import org.onlab.packet.DeserializationException;
22import org.onlab.packet.Ethernet;
23import org.onlab.packet.MacAddress;
24import org.onosproject.net.packet.OutboundPacket;
25import org.onosproject.net.packet.PacketServiceAdapter;
26
27import java.util.Map;
28
29/**
30 * Mock Packet Service.
31 * It is used for tests related to packet-ins management.
32 */
33public class MockPacketService extends PacketServiceAdapter {
34
35 private final Map<MacAddress, Pair<OutboundPacket, Ethernet>> outBoundPackets = Maps.newHashMap();
36
37 @Override
38 public void emit(OutboundPacket packet) {
39 try {
40 Ethernet ethernetPacket = Ethernet.deserializer().deserialize(packet.data().array(),
41 packet.data().arrayOffset(),
42 packet.data().array().length);
43 outBoundPackets.put(ethernetPacket.getDestinationMAC(), Pair.of(packet, ethernetPacket));
44 } catch (DeserializationException e) {
45
46 }
47 }
48
49 Ethernet getEthernetPacket(MacAddress key) {
50 Pair<OutboundPacket, Ethernet> pair = outBoundPackets.get(key);
51 return pair != null ? pair.getRight() : null;
52 }
53}