@@ -0,0 +1,3690 @@
+/*%0A * Copyright 2015 Open Networking Laboratory%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.onosproject.vtn.table.impl;%0A%0Aimport static com.google.common.base.Preconditions.checkNotNull;%0Aimport static org.slf4j.LoggerFactory.getLogger;%0A%0Aimport org.onlab.osgi.DefaultServiceDirectory;%0Aimport org.onlab.osgi.ServiceDirectory;%0Aimport org.onlab.packet.Ethernet;%0Aimport org.onlab.packet.IpAddress;%0Aimport org.onlab.packet.IpPrefix;%0Aimport org.onlab.packet.MacAddress;%0Aimport org.onosproject.core.ApplicationId;%0Aimport org.onosproject.net.DeviceId;%0Aimport org.onosproject.net.flow.DefaultTrafficSelector;%0Aimport org.onosproject.net.flow.DefaultTrafficTreatment;%0Aimport org.onosproject.net.flow.TrafficSelector;%0Aimport org.onosproject.net.flow.TrafficTreatment;%0Aimport org.onosproject.net.flowobjective.DefaultForwardingObjective;%0Aimport org.onosproject.net.flowobjective.FlowObjectiveService;%0Aimport org.onosproject.net.flowobjective.ForwardingObjective;%0Aimport org.onosproject.net.flowobjective.ForwardingObjective.Flag;%0Aimport org.onosproject.net.flowobjective.Objective;%0Aimport org.onosproject.vtn.table.DnatService;%0Aimport org.onosproject.vtnrsc.SegmentationId;%0Aimport org.slf4j.Logger;%0A%0A/**%0A * Provides implementation of DnatService.%0A */%0Apublic class DnatServiceImpl implements DnatService %7B%0A    private final Logger log = getLogger(getClass());%0A%0A    private static final int DNAT_PRIORITY = 0xffff;%0A    private static final int PREFIX_LENGTH = 32;%0A%0A    private final FlowObjectiveService flowObjectiveService;%0A    private final ApplicationId appId;%0A%0A    /**%0A     * Construct a DnatServiceImpl object.%0A     *%0A     * @param appId the application id of vtn%0A     */%0A    public DnatServiceImpl(ApplicationId appId) %7B%0A        this.appId = checkNotNull(appId, %22ApplicationId can not be null%22);%0A        ServiceDirectory serviceDirectory = new DefaultServiceDirectory();%0A        this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class);%0A    %7D%0A%0A    @Override%0A    public void programRules(DeviceId deviceId, IpAddress dstIp,%0A                             MacAddress ethSrc, IpAddress ipDst,%0A                             SegmentationId actionVni, Objective.Operation type) %7B%0A        TrafficSelector selector = DefaultTrafficSelector.builder()%0A                .matchEthType(Ethernet.TYPE_IPV4)%0A                .matchIPDst(IpPrefix.valueOf(dstIp, PREFIX_LENGTH)).build();%0A%0A        TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();%0A        treatment.setEthSrc(ethSrc).setIpDst(ipDst)%0A                .setTunnelId(Long.parseLong(actionVni.segmentationId()));%0A        ForwardingObjective.Builder objective = DefaultForwardingObjective%0A                .builder().withTreatment(treatment.build())%0A                .withSelector(selector).fromApp(appId).withFlag(Flag.SPECIFIC)%0A                .withPriority(DNAT_PRIORITY);%0A        if (type.equals(Objective.Operation.ADD)) %7B%0A            log.debug(%22RouteRules--%3EADD%22);%0A            flowObjectiveService.forward(deviceId, objective.add());%0A        %7D else %7B%0A            log.debug(%22RouteRules--%3EREMOVE%22);%0A            flowObjectiveService.forward(deviceId, objective.remove());%0A        %7D%0A    %7D%0A%7D%0A

Add the implementation of DnatService interface.