Bug 5540 - PortConvertor, MatchConvertor
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / action / ActionSetNwDstConvertorV10Impl.java
1 /**
2  * Copyright (c) 2013 Ericsson. 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
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action;
10
11 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4;
16
17 /**
18  * Utility class for converting a MD-SAL action subelement into the OF subelement
19  */
20 public class ActionSetNwDstConvertorV10Impl implements Convertor<SetNwDstActionCase, Object> {
21
22     @Override
23     public Class<?> getType() {
24         return SetNwDstActionCase.class;
25     }
26
27     @Override
28     public Object convert(SetNwDstActionCase source) {
29         Address address = source.getSetNwDstAction().getAddress();
30         if (address instanceof Ipv4) {
31             //FIXME use of substring should be removed and OF models should distinguish where
32             //FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask)
33
34             String ipAddress = ((Ipv4) address).getIpv4Address().getValue();
35             ipAddress = ipAddress.substring(0, ipAddress.indexOf("/"));
36             return new Ipv4Address(ipAddress);
37         } else {
38             throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName());
39         }
40     }
41 }