blob: 9161ee6f38bdae97f0ce2e71f03064d291870f66 [file] [log] [blame]
William Davies5bae5052019-10-19 01:25:01 -07001/*
2 * Copyright 2015-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 */
16package org.onosproject.fpm.web;
17
18
19import com.fasterxml.jackson.databind.node.ObjectNode;
20import org.onosproject.codec.CodecContext;
21import org.onosproject.codec.JsonCodec;
22import org.onosproject.routing.fpm.FpmPeer;
23
24import org.onlab.packet.IpAddress;
25import org.onosproject.routing.fpm.FpmPeerAcceptRoutes;
26
27/**
28 * Codec of FpmPeerInfo class.
29 */
30public final class FpmAcceptRoutesCodec extends JsonCodec<FpmPeerAcceptRoutes> {
31
32 // JSON field names
33 private static final String PEER_ADDRESS = "peerAddress";
34 private static final String PEER_PORT = "peerPort";
35 private static final String ACCEPT_ROUTES = "acceptRoutes";
36
37 @Override
38 public FpmPeerAcceptRoutes decode(ObjectNode json, CodecContext context) {
39 if (json == null || !json.isObject()) {
40 return null;
41 }
42
43 IpAddress address = IpAddress.valueOf(json.path(PEER_ADDRESS).asText());
44 int port = Integer.parseInt(json.path(PEER_PORT).asText());
45 boolean isAcceptRoutes = Boolean.valueOf(json.path(ACCEPT_ROUTES).asText());
46 FpmPeer peer = new FpmPeer(address, port);
47 FpmPeerAcceptRoutes updatedPeer = new FpmPeerAcceptRoutes(peer, isAcceptRoutes);
48 return updatedPeer;
49 }
50}