6c5cc2e85b809fbdb0d78e129a3994108bac4dcd
[onosfw.git] /
1 /*\r
2  * Copyright 2015 Open Networking Laboratory\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 package org.onosproject.vtnrsc.web;\r
17 \r
18 import static com.google.common.base.Preconditions.checkNotNull;\r
19 \r
20 import org.onosproject.codec.CodecContext;\r
21 import org.onosproject.codec.JsonCodec;\r
22 import org.onosproject.vtnrsc.AllowedAddressPair;\r
23 \r
24 import com.fasterxml.jackson.databind.node.ObjectNode;\r
25 \r
26 /**\r
27  * VirtualPort AllowedAddressPair codec.\r
28  */\r
29 public final class AllowedAddressPairCodec extends JsonCodec<AllowedAddressPair> {\r
30 \r
31     @Override\r
32     public ObjectNode encode(AllowedAddressPair alocAddPair, CodecContext context) {\r
33         checkNotNull(alocAddPair, "AllowedAddressPair cannot be null");\r
34         ObjectNode result = context.mapper().createObjectNode()\r
35                 .put("ip_address", alocAddPair.ip().toString())\r
36                 .put("mac_address", alocAddPair.mac().toString());\r
37         return result;\r
38     }\r
39 \r
40 }\r