2 * Copyright (c) 2016 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
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases;
11 import java.util.Optional;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.openflowplugin.api.OFConstants;
14 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData;
15 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.dst._case.SetNwDstActionBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
25 public class SalToOfSetNwDstActionV10Case extends ConvertorCase<SetNwDstActionCase, Action, ActionConvertorData> {
26 public SalToOfSetNwDstActionV10Case() {
27 super(SetNwDstActionCase.class, true, OFConstants.OFP_VERSION_1_0);
32 public Optional<Action> process(@Nonnull final SetNwDstActionCase source, final ActionConvertorData data) {
33 final ActionBuilder builder = new ActionBuilder();
34 final Address address = source.getSetNwDstAction().getAddress();
36 if (address instanceof Ipv4) {
37 //FIXME use of substring should be removed and OF models should distinguish where
38 //FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask)
40 String ipAddress = ((Ipv4) address).getIpv4Address().getValue();
41 ipAddress = ipAddress.substring(0, ipAddress.indexOf("/"));
42 Ipv4Address result = new Ipv4Address(ipAddress);
43 SetNwDstCaseBuilder setNwDstCaseBuilder = new SetNwDstCaseBuilder();
44 SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
45 setNwDstActionBuilder.setIpAddress(result);
46 setNwDstCaseBuilder.setSetNwDstAction(setNwDstActionBuilder.build());
47 builder.setActionChoice(setNwDstCaseBuilder.build());
49 throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName());
52 return Optional.of(builder.build());