2 * Copyright (c) 2013 Ericsson. 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.openflowplugin.openflow.md.core.sal.convertor.action;
11 import com.google.common.base.Splitter;
12 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6;
21 * Utility class for converting a MD-SAL action subelement into the OF subelement
23 public class ActionSetNwSrcConvertorImpl implements Convertor<SetNwSrcActionCase, Object> {
25 private static final Splitter PREFIX_SPLITTER = Splitter.on('/');
28 public Class<?> getType() {
29 return SetNwSrcActionCase.class;
33 public Object convert(final SetNwSrcActionCase source) {
34 Address address = source.getSetNwSrcAction().getAddress();
35 if (address instanceof Ipv4) {
36 Iterable<String> addressParts = PREFIX_SPLITTER.split(((Ipv4) address).getIpv4Address().getValue());
37 return new Ipv4Address(addressParts.iterator().next());
38 } else if (address instanceof Ipv6) {
39 Iterable<String> addressParts = PREFIX_SPLITTER.split(((Ipv6) address).getIpv6Address().getValue());
40 return new Ipv6Address(addressParts.iterator().next());
42 throw new IllegalArgumentException("Address is not supported: "+address.getClass().getName());