blob: b0525185a37be3ed2d92457307e9545ecdfda2ad [file] [log] [blame]
Jian Li44155b02017-02-15 17:03:38 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Li44155b02017-02-15 17:03:38 +09003 *
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 */
16package org.onosproject.mapping;
17
18import org.onlab.packet.IpPrefix;
19import org.onosproject.mapping.actions.MappingAction;
20import org.onosproject.mapping.actions.MappingActions;
21import org.onosproject.mapping.addresses.MappingAddress;
22import org.onosproject.mapping.addresses.MappingAddresses;
Jian Li98763102017-02-19 23:48:46 +090023import org.onosproject.net.DeviceId;
Jian Li44155b02017-02-15 17:03:38 +090024
25import java.util.Collections;
26import java.util.List;
Jian Li98763102017-02-19 23:48:46 +090027import java.util.Objects;
Jian Li44155b02017-02-15 17:03:38 +090028
29/**
30 * Commons mocks used by the mapping management tasks.
31 */
32public 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 Li98763102017-02-19 23:48:46 +090063
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 Li44155b02017-02-15 17:03:38 +0900125}