/** * Copyright (c) 2013 Ericsson. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action; import java.math.BigInteger; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6; import com.google.common.base.Splitter; /** * Utility class for converting a MD-SAL action subelement into the OF subelement */ public class ActionSetNwSrcConvertorImpl implements Convertor { private static final Splitter PREFIX_SPLITTER = Splitter.on('/'); @Override public Object convert(final SetNwSrcActionCase source, final BigInteger datapathid) { Address address = source.getSetNwSrcAction().getAddress(); if (address instanceof Ipv4) { Iterable addressParts = PREFIX_SPLITTER.split(((Ipv4) address).getIpv4Address().getValue()); return new Ipv4Address(addressParts.iterator().next()); } else if (address instanceof Ipv6) { Iterable addressParts = PREFIX_SPLITTER.split(((Ipv6) address).getIpv6Address().getValue()); return new Ipv6Address(addressParts.iterator().next()); } else { throw new IllegalArgumentException("Address is not supported: "+address.getClass().getName()); } } }