Jian Li | 44155b0 | 2017-02-15 17:03:38 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jian Li | 44155b0 | 2017-02-15 17:03:38 +0900 | [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 | package org.onosproject.mapping; |
| 17 | |
| 18 | import org.onlab.packet.IpPrefix; |
| 19 | import org.onosproject.mapping.actions.MappingAction; |
| 20 | import org.onosproject.mapping.actions.MappingActions; |
| 21 | import org.onosproject.mapping.addresses.MappingAddress; |
| 22 | import org.onosproject.mapping.addresses.MappingAddresses; |
Jian Li | 9876310 | 2017-02-19 23:48:46 +0900 | [diff] [blame] | 23 | import org.onosproject.net.DeviceId; |
Jian Li | 44155b0 | 2017-02-15 17:03:38 +0900 | [diff] [blame] | 24 | |
| 25 | import java.util.Collections; |
| 26 | import java.util.List; |
Jian Li | 9876310 | 2017-02-19 23:48:46 +0900 | [diff] [blame] | 27 | import java.util.Objects; |
Jian Li | 44155b0 | 2017-02-15 17:03:38 +0900 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Commons mocks used by the mapping management tasks. |
| 31 | */ |
| 32 | public class MappingTestMocks { |
| 33 | |
| 34 | private static final String IP = "1.2.3.4/24"; |
| 35 | |
| 36 | /** |
| 37 | * Mock mapping key class used for satisfying API requirements. |
| 38 | */ |
| 39 | public static class MockMappingKey implements MappingKey { |
| 40 | |
| 41 | @Override |
| 42 | public MappingAddress address() { |
| 43 | IpPrefix ip = IpPrefix.valueOf(IP); |
| 44 | return MappingAddresses.ipv4MappingAddress(ip); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Mock mapping value class used for satisfying API requirements. |
| 50 | */ |
| 51 | public static class MockMappingValue implements MappingValue { |
| 52 | |
| 53 | @Override |
| 54 | public MappingAction action() { |
| 55 | return MappingActions.noAction(); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public List<MappingTreatment> treatments() { |
| 60 | return Collections.emptyList(); |
| 61 | } |
| 62 | } |
Jian Li | 9876310 | 2017-02-19 23:48:46 +0900 | [diff] [blame] | 63 | |
| 64 | private static final MockMappingKey MAPPING_KEY = new MockMappingKey(); |
| 65 | private static final MockMappingValue MAPPING_VALUE = new MockMappingValue(); |
| 66 | |
| 67 | /** |
| 68 | * Mock mapping class used for satisfying API requirements. |
| 69 | */ |
| 70 | public static class MockMapping implements Mapping { |
| 71 | |
| 72 | static int nextId = 0; |
| 73 | |
| 74 | int id; |
| 75 | long timestamp; |
| 76 | |
| 77 | public MockMapping() { |
| 78 | this.id = nextId++; |
| 79 | this.timestamp = System.currentTimeMillis(); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public MappingId id() { |
| 84 | return MappingId.valueOf(id); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public short appId() { |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public DeviceId deviceId() { |
| 94 | return DeviceId.deviceId("lisp:" + id); |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public MappingKey key() { |
| 99 | return MAPPING_KEY; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public MappingValue value() { |
| 104 | return MAPPING_VALUE; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public int hashCode() { |
| 109 | return id; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public boolean equals(Object obj) { |
| 114 | if (this == obj) { |
| 115 | return true; |
| 116 | } |
| 117 | if (obj == null || getClass() != obj.getClass()) { |
| 118 | return false; |
| 119 | } |
| 120 | final MockMapping other = (MockMapping) obj; |
| 121 | return Objects.equals(this.timestamp, other.timestamp) && |
| 122 | this.id == other.id; |
| 123 | } |
| 124 | } |
Jian Li | 44155b0 | 2017-02-15 17:03:38 +0900 | [diff] [blame] | 125 | } |