2 * Copyright (c) 2014 Cisco Systems, 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
8 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor;
10 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
16 public final class IpConverter {
18 public static long Ipv4AddressToLong(Ipv4Address ipv4Address) {
19 String ipAddress = ipv4Address.getValue();
21 String[] atoms = ipAddress.split("\\.");
22 for (int i = 3; i >= 0; i--) {
23 result |= (Long.parseLong(atoms[3 - i]) << (i * 8));
25 return result & 0xFFFFFFFF;
28 public static Ipv4Address longToIpv4Address(long ip) {
30 StringBuilder sb = new StringBuilder(15);
31 for (int i = 0; i < 4; i++) {
32 sb.insert(0, Long.toString(tmpIp & 0xff));
38 return new Ipv4Address(sb.toString());