/*
* Copyright (C) 2014 Red Hat, Inc.
*
* 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
*
* Authors : Sam Hague
*/
package org.opendaylight.ovsdb.ovssfc;

import com.google.common.base.Optional;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
//import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunction;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.ovs.rev140701.ServiceFunctionForwarder1;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.ovs.rev140701.service.function.forwarders.service.function.forwarder.ovs.ExternalIds;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.ExecutionException;

public class SffUtils {
    private static final Logger logger = LoggerFactory.getLogger(SffUtils.class);

    public ServiceFunctionForwarder readServiceFunctionForwarder (String name) {
        InstanceIdentifier<ServiceFunctionForwarder> iID =
                InstanceIdentifierUtils.createServiceFunctionForwarderPath(name);

        ReadOnlyTransaction readTx = OvsSfcProvider.getOvsSfcProvider().getDataBroker().newReadOnlyTransaction();
        Optional<ServiceFunctionForwarder> dataObject = null;
        try {
            dataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, iID).get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
        if ((dataObject != null) && (dataObject.get() != null)) {
            logger.trace("\nOVSSFC Exit: {}\n   sff: {}",
                    Thread.currentThread().getStackTrace()[1], dataObject.get().toString());
            return dataObject.get();
        } else {
            logger.trace("\nOVSSFC Exit: {}, sff: null", Thread.currentThread().getStackTrace()[1]);
            return null;
        }
    }

    public String getSystemId (ServiceFunctionForwarder serviceFunctionForwarder) {
        String systemId = "";

        List<ExternalIds> externalIds = serviceFunctionForwarder.getAugmentation(ServiceFunctionForwarder1.class).getOvs().getExternalIds();
        for (ExternalIds externalId : externalIds) {
            if (externalId.getName().equals("system-id")) {
                systemId = externalId.getValue();
            }
        }

        logger.trace("\nOVSSFC {}\n system-id: {}",
                Thread.currentThread().getStackTrace()[1],
                systemId);

        return systemId;
    }
}

@@ -629,24 +629,26 @@
 ceFunction;%0A
+//
 import org.o
@@ -749,16 +749,18 @@
 arder1;%0A
+//
 import o
@@ -1172,16 +1172,18 @@
 ctory;%0A%0A
+//
 import j
@@ -2495,16 +2495,18 @@
         
+//
 List%3CExt
@@ -2638,16 +2638,18 @@
         
+//
 for (Ext
@@ -2689,24 +2689,26 @@
 ) %7B%0A        
+//
     if (exte
@@ -2747,32 +2747,34 @@
 id%22)) %7B%0A        
+//
         systemId
@@ -2803,24 +2803,26 @@
 ();%0A        
+//
     %7D%0A      
@@ -2819,24 +2819,26 @@
   %7D%0A        
+//
 %7D%0A%0A        l

Add workaround because sfc models changed.