2 * Copyright (c) 2013, 2015 Red Hat, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.plugin.md;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 import java.net.Inet4Address;
19 import java.net.InetAddress;
22 * Utilities to convert Java types to the types specified in the Yang models
24 public final class Utils {
26 static final Logger logger = LoggerFactory.getLogger(Utils.class);
29 * Returns a {@link org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress}
30 * from a @{link java.net.InetAddress}
32 public static IpAddress convertIpAddress(InetAddress inetAddress){
34 if (inetAddress instanceof Inet4Address){
35 Ipv4Address ipv4Address = new Ipv4Address(inetAddress.getHostAddress());
36 return new IpAddress(ipv4Address);
39 Ipv6Address ipv6Address = new Ipv6Address(inetAddress.getHostAddress());
40 return new IpAddress(ipv6Address);