Move integration tests to mdsal-it-parent
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / util / MapRequestUtil.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.lispflowmapping.implementation.util;
9
10 import java.net.InetAddress;
11 import java.net.UnknownHostException;
12
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.MapRequest;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer.Address;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer.address.Ipv4;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer.address.Ipv6;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.maprequest.ItrRloc;
18
19 public class MapRequestUtil {
20     public static InetAddress selectItrRloc(MapRequest request) {
21         if (request.getItrRloc() == null) {
22             return null;
23         }
24         InetAddress selectedItrRloc = null;
25         for (ItrRloc itr : request.getItrRloc()) {
26             Address addr = itr.getLispAddressContainer().getAddress();
27             if (addr instanceof Ipv4) {
28                 try {
29                     selectedItrRloc = InetAddress.getByName(((Ipv4) addr).getIpv4Address().getIpv4Address().getValue());
30                 } catch (UnknownHostException e) {
31                 }
32                 break;
33             }
34             if (addr instanceof Ipv6) {
35                 try {
36                     selectedItrRloc = InetAddress.getByName((((Ipv6) addr).getIpv6Address().getIpv6Address().getValue()));
37                 } catch (UnknownHostException e) {
38                 }
39                 break;
40             }
41         }
42         return selectedItrRloc;
43     }
44 }