Example usage for com.google.gson JsonPrimitive getAsString

List of usage examples for com.google.gson JsonPrimitive getAsString

Introduction

In this page you can find the example usage for com.google.gson JsonPrimitive getAsString.

Prototype

@Override
public String getAsString() 

Source Link

Document

convenience method to get this element as a String.

Usage

From source file:org.moe.tools.natjgen.Bindings.java

License:Apache License

@Override
public void setJsonObject(JsonObject json) {
    setOutputDirectory(null);//  w w w .jav a 2  s .  co m
    final JsonPrimitive jsonOutput = json.getAsJsonPrimitive("output");
    if (jsonOutput != null) {
        setOutputDirectory(jsonOutput.getAsString());
    }

    setPlatform(null);
    final JsonPrimitive jsonPlatform = json.getAsJsonPrimitive("platform");
    if (jsonPlatform != null) {
        setPlatform(jsonPlatform.getAsString());
    }

    setTypeConfigInput(null);
    final JsonPrimitive jsonTypeConfigInput = json.getAsJsonPrimitive("type-config-input");
    if (jsonTypeConfigInput != null) {
        setTypeConfigInput(jsonTypeConfigInput.getAsString());
    }

    setTypeConfigOutput(null);
    final JsonPrimitive jsonTypeConfigOutput = json.getAsJsonPrimitive("type-config-output");
    if (jsonTypeConfigOutput != null) {
        setTypeConfigOutput(jsonTypeConfigOutput.getAsString());
    }

    setInlineFunctionBindingOutput(null);
    final JsonPrimitive jsonInlineFunctionBindingOutput = json
            .getAsJsonPrimitive("inline-function-binding-output");
    if (jsonInlineFunctionBindingOutput != null) {
        setInlineFunctionBindingOutput(jsonInlineFunctionBindingOutput.getAsString());
    }

    bindings.clear();
    final JsonArray jsonBindings = json.getAsJsonArray("bindings");
    if (jsonBindings != null) {
        for (JsonElement jsonBinding : jsonBindings) {
            final JsonObject element = (JsonObject) jsonBinding;
            final String type = element.getAsJsonPrimitive("type").getAsString();
            if ("framework".equals(type)) {
                FrameworkBinding binding = new FrameworkBinding();
                binding.setJsonObject(element);
                bindings.add(binding);

            } else if ("header".equals(type)) {
                HeaderBinding binding = new HeaderBinding();
                binding.setJsonObject(element);
                bindings.add(binding);

            } else {
                throw new RuntimeException("unrecognized binding type " + type);
            }
        }
    }
}

From source file:org.moe.tools.natjgen.FrameworkBinding.java

License:Apache License

@Override
public void setJsonObject(JsonObject json) {
    super.setJsonObject(json);

    setFrameworkPath(null);//from ww  w.  j a  va  2 s  . co  m
    final JsonPrimitive jsonFrameworkPath = json.getAsJsonPrimitive("frameworkPath");
    if (jsonFrameworkPath != null) {
        setFrameworkPath(jsonFrameworkPath.getAsString());
    }

    setPackageBase(null);
    final JsonPrimitive jsonPackageBase = json.getAsJsonPrimitive("packageBase");
    if (jsonPackageBase != null) {
        setPackageBase(jsonPackageBase.getAsString());
    }

    setImportCode(null);
    final JsonPrimitive jsonImportCode = json.getAsJsonPrimitive("importCode");
    if (jsonImportCode != null) {
        setImportCode(jsonImportCode.getAsString());
    }
}

From source file:org.moe.tools.natjgen.HeaderBinding.java

License:Apache License

@Override
public void setJsonObject(JsonObject json) {
    super.setJsonObject(json);

    setHeaderPath(null);/*w  ww  . j  a v  a  2  s.  c om*/
    final JsonPrimitive jsonHeaderPath = json.getAsJsonPrimitive("headerPath");
    if (jsonHeaderPath != null) {
        setHeaderPath(jsonHeaderPath.getAsString());
    }

    readJsonStringArray(json.getAsJsonArray("headerSearchPaths"), headerSearchPaths);
    readJsonStringArray(json.getAsJsonArray("userHeaderSearchPaths"), userHeaderSearchPaths);
    readJsonStringArray(json.getAsJsonArray("frameworkSearchPaths"), frameworkSearchPaths);

    setPackageBase(null);
    final JsonPrimitive jsonPackageBase = json.getAsJsonPrimitive("packageBase");
    if (jsonPackageBase != null) {
        setPackageBase(jsonPackageBase.getAsString());
    }

    setImportCode(null);
    final JsonPrimitive jsonImportCode = json.getAsJsonPrimitive("importCode");
    if (jsonImportCode != null) {
        setImportCode(jsonImportCode.getAsString());
    }

    setExplicitLibrary(null);
    final JsonPrimitive jsonExplicitLibrary = json.getAsJsonPrimitive("explicitLibrary");
    if (jsonExplicitLibrary != null) {
        setExplicitLibrary(jsonExplicitLibrary.getAsString());
    }
}

From source file:org.nordapp.web.util.GsonHashMapDeserializer.java

License:Apache License

private Object handlePrimitive(JsonPrimitive json) {
    if (json.isBoolean())
        return json.getAsBoolean();
    else if (json.isString())
        return json.getAsString();
    else {//  w  w w .  j  a v a 2  s. c o  m
        BigDecimal bigDec = json.getAsBigDecimal();
        if (json.getAsString().indexOf('.') == -1) {
            // Find out if it is an int type
            try {
                return bigDec.longValue();
            } catch (ArithmeticException e) {
            }
        }
        // Just return it as a double
        return bigDec.doubleValue();
    }
}

From source file:org.openbaton.integration.test.parser.Parser.java

License:Apache License

private static boolean checkCompatibility(JsonElement elementValue) {
    if (elementValue instanceof JsonPrimitive) {
        JsonPrimitive jsonPrimitive = (JsonPrimitive) elementValue;
        if (jsonPrimitive.isString())
            if (jsonPrimitive.getAsString().startsWith("<::") && jsonPrimitive.getAsString().endsWith("::>")) {
                return true;
            }// w  ww. jav  a 2s  .  com
    }
    return false;
}

From source file:org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeReader.java

License:Open Source License

private static void addChildToParent(final String childName, final JsonElement childType,
        final CompositeNodeWrapper parent) {
    if (childType.isJsonObject()) {
        CompositeNodeWrapper child = new CompositeNodeWrapper(getNamespaceFor(childName),
                getLocalNameFor(childName));
        parent.addValue(child);//  w w w.j a v  a 2  s  . c  o m
        for (Entry<String, JsonElement> childOfChild : childType.getAsJsonObject().entrySet()) {
            addChildToParent(childOfChild.getKey(), childOfChild.getValue(), child);
        }
    } else if (childType.isJsonArray()) {
        if (childType.getAsJsonArray().size() == 1 && childType.getAsJsonArray().get(0).isJsonNull()) {
            parent.addValue(new EmptyNodeWrapper(getNamespaceFor(childName), getLocalNameFor(childName)));

        } else {
            for (JsonElement childOfChildType : childType.getAsJsonArray()) {
                addChildToParent(childName, childOfChildType, parent);
            }
        }
    } else if (childType.isJsonPrimitive()) {
        JsonPrimitive childPrimitive = childType.getAsJsonPrimitive();
        String value = childPrimitive.getAsString().trim();
        parent.addValue(new SimpleNodeWrapper(getNamespaceFor(childName), getLocalNameFor(childName),
                resolveValueOfElement(value)));
    } else {
        LOG.debug("Ignoring unhandled child type {}", childType);
    }
}

From source file:org.opendaylight.vtn.javaapi.ipc.conversion.IpcLogicalResponseFactory.java

License:Open Source License

/**
 * This method is Used to generate Match Flow info Json
 * //from  ww  w. j  a v a  2  s .c om
 * @param responsePacket
 * @param requestBody
 * @param getType
 * @return JsonObject
 */
private JsonObject getDataFlowMatchInfo(final IpcDataUnit[] responsePacket, final AtomicInteger index,
        final byte validBit, final JsonObject controlerFlow, final IpcStruct valDfDataFlowCmnStruct) {
    LOG.trace("getDataFlowMatchInfo started");
    final int matchCount = Integer.parseInt(IpcDataUnitWrapper.getIpcStructUint32Value(valDfDataFlowCmnStruct,
            VtnServiceIpcConsts.MATCH_COUNT));
    LOG.debug("MATCH_COUNT:" + matchCount);
    // match JsonObject will hold all below jsonObject as per requiremnts
    final JsonObject match = new JsonObject();

    JsonArray inportJsonArray = null;
    JsonArray srcMacJsonArray = null;
    JsonArray dstMacJsonArray = null;
    JsonArray srcMaskJsonArray = null;
    JsonArray dstMaskJsonArray = null;
    JsonArray macEtherTypeJsonArray = null;
    JsonArray vlanIdJsonArray = null;
    JsonArray vlanPriorityJsonArray = null;
    JsonArray ipTosJsonArray = null;
    JsonArray ipProtoJsonArray = null;
    JsonArray ipDstAddrJsonArray = null;
    JsonArray ipDstAddrMaskJsonArray = null;
    JsonArray ipSrcAddrJsonArray = null;
    JsonArray ipSrcAddrMaskJsonArray = null;
    JsonArray l4DstPortIcmpTypeJsonArray = null;
    JsonArray l4DstPortIcmpTypeMaskJsonArray = null;
    JsonArray l4SrcPortIcmpTypeJsonArray = null;
    JsonArray l4SrcPortIcmpTypeMaskJsonArray = null;
    JsonArray ipV6DstAddJsonArray = null;
    JsonArray ipV6DstAddrMaskJsonArray = null;
    JsonArray ipV6SrcAddrJsonArray = null;
    JsonArray ipV6SrcAddrMaskJsonArray = null;
    JsonPrimitive element = null;
    for (int i = 0; i < matchCount; i++) {
        final IpcStruct valDfFlowMatchStruct = (IpcStruct) responsePacket[index.getAndIncrement()];

        final int matchtype = Integer.parseInt(IpcDataUnitWrapper.getIpcStructUint32Value(valDfFlowMatchStruct,
                VtnServiceIpcConsts.MATCH_TYPE));
        LOG.debug("MATCH TYPE:" + matchtype);
        // match type will help in resolving response in match info
        if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IN_PORT.ordinal()) {
            final IpcStruct valDfFlowMatchInPort = (IpcStruct) responsePacket[index.getAndIncrement()];
            // set inport
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint32Value(valDfFlowMatchInPort, VtnServiceIpcConsts.IN_PORT).toString());

            if (null == inportJsonArray) {
                inportJsonArray = new JsonArray();
            }
            inportJsonArray.add(element);
            LOG.debug("set validBit for in_port :" + validBit);

        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_DL_DST.ordinal()) {
            final IpcStruct valDfFlowMatchDlAddr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(
                    IpcDataUnitWrapper.getMacAddress(valDfFlowMatchDlAddr, VtnServiceIpcConsts.DL_ADDR));
            if (null == dstMacJsonArray) {
                dstMacJsonArray = new JsonArray();
            }
            dstMacJsonArray.add(element);
            LOG.debug("set validbit for macdst :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valDfFlowMatchDlAddr,
                    VtnServiceIpcConsts.V_MASK);

            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getMacAddress(valDfFlowMatchDlAddr, VtnServiceIpcConsts.DL_ADDR_MASK).toString());
                if (null == dstMaskJsonArray) {
                    dstMaskJsonArray = new JsonArray();
                }
                dstMaskJsonArray.add(element);
                LOG.debug("set validbit for macdst :" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_DL_SRC.ordinal()) {
            final IpcStruct valDfFlowMatchDlAddr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getMacAddress(valDfFlowMatchDlAddr, VtnServiceIpcConsts.DL_ADDR).toString());
            if (null == srcMacJsonArray) {
                srcMacJsonArray = new JsonArray();
            }
            srcMacJsonArray.add(element);
            LOG.debug("set validbit for macsrc  :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valDfFlowMatchDlAddr,
                    VtnServiceIpcConsts.V_MASK);

            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getMacAddress(valDfFlowMatchDlAddr, VtnServiceIpcConsts.DL_ADDR_MASK).toString());
                if (null == srcMaskJsonArray) {
                    srcMaskJsonArray = new JsonArray();
                }
                srcMaskJsonArray.add(element);
                LOG.debug("set validbit for macdst  :" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_DL_TYPE.ordinal()) {
            final IpcStruct valDfFlowMatchDlType = (IpcStruct) responsePacket[index.getAndIncrement()];
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16HexaValue(valDfFlowMatchDlType, VtnServiceIpcConsts.DL_TYPE).toString());
            if (null == macEtherTypeJsonArray) {
                macEtherTypeJsonArray = new JsonArray();
            }
            macEtherTypeJsonArray.add(element);
            LOG.debug("set validbit for etherntype :" + validBit);

        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_VLAN_ID.ordinal()) {
            final IpcStruct valDfFlowMatchVlanVid = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowMatchVlanVid, VtnServiceIpcConsts.VLAN_ID).toString());
            if (null == vlanIdJsonArray) {
                vlanIdJsonArray = new JsonArray();
            }
            if (element.getAsString().equals(VtnServiceJsonConsts.VLAN_ID_65535)) {
                element = new JsonPrimitive(VtnServiceJsonConsts.EMPTY);
                vlanIdJsonArray.add(element);
            } else {
                vlanIdJsonArray.add(element);
            }

            LOG.debug("set validbit for vlan_id  :" + validBit);

        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_VLAN_PCP.ordinal()) {
            final IpcStruct valDfFlowMatchVlanpcp = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint8Value(valDfFlowMatchVlanpcp, VtnServiceIpcConsts.VLAN_PCP).toString());
            if (null == vlanPriorityJsonArray) {
                vlanPriorityJsonArray = new JsonArray();
            }
            vlanPriorityJsonArray.add(element);
            LOG.debug("set validbit for vlanpriority  :" + validBit);

        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IP_TOS.ordinal()) {

            final IpcStruct valDfFlowMatchIpTos = (IpcStruct) responsePacket[index.getAndIncrement()];

            final String hexString = UnsignedInteger.toHexString(Long.valueOf(IpcDataUnitWrapper
                    .getIpcStructUint8Value(valDfFlowMatchIpTos, VtnServiceIpcConsts.IP_TOS)));
            element = new JsonPrimitive("0x" + hexString);
            if (null == ipTosJsonArray) {
                ipTosJsonArray = new JsonArray();
            }
            ipTosJsonArray.add(element);
            LOG.debug("set validbit for iptos :" + validBit);

        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IP_PROTO.ordinal()) {

            final IpcStruct valDfFlowMatchIpProto = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint8Value(valDfFlowMatchIpProto, VtnServiceIpcConsts.IP_PROTO).toString());
            if (null == ipProtoJsonArray) {
                ipProtoJsonArray = new JsonArray();
            }
            ipProtoJsonArray.add(element);
            LOG.debug("set validbit for  ipproto :" + validBit);

        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IPV4_SRC.ordinal()) {
            final IpcStruct valDfFlowMatchIpv4Addr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructIpv4Value(valDfFlowMatchIpv4Addr, VtnServiceIpcConsts.IPV4_ADDR).toString());
            if (null == ipSrcAddrJsonArray) {
                ipSrcAddrJsonArray = new JsonArray();
            }
            ipSrcAddrJsonArray.add(element);
            LOG.debug("set validbit for ipsrc :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valDfFlowMatchIpv4Addr,
                    VtnServiceIpcConsts.V_MASK);
            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getIpcStructIpv4Value(valDfFlowMatchIpv4Addr, VtnServiceIpcConsts.IPV4_ADDR_MASK)
                        .toString());
                if (null == ipSrcAddrMaskJsonArray) {
                    ipSrcAddrMaskJsonArray = new JsonArray();

                }
                ipSrcAddrMaskJsonArray.add(element);
                LOG.debug("set validBit for ipv4_mask:" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IPV4_DST.ordinal()) {
            final IpcStruct valDfFlowMatchIpv4Addr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructIpv4Value(valDfFlowMatchIpv4Addr, VtnServiceIpcConsts.IPV4_ADDR).toString());
            if (null == ipDstAddrJsonArray) {
                ipDstAddrJsonArray = new JsonArray();
            }
            ipDstAddrJsonArray.add(element);
            LOG.debug("set validbit for ipdst  :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valDfFlowMatchIpv4Addr,
                    VtnServiceIpcConsts.V_MASK);
            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getIpcStructIpv4Value(valDfFlowMatchIpv4Addr, VtnServiceIpcConsts.IPV4_ADDR_MASK)
                        .toString());
                if (null == ipDstAddrMaskJsonArray) {
                    ipDstAddrMaskJsonArray = new JsonArray();
                }
                ipDstAddrMaskJsonArray.add(element);
                LOG.debug("set validbit for ipv4_mask:" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IPV6_SRC.ordinal()) {

            final IpcStruct valdfflowmatchIpv6Addr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructIpv6Value(valdfflowmatchIpv6Addr, VtnServiceIpcConsts.IPV6_ADDR).toString());
            if (null == ipV6SrcAddrJsonArray) {
                ipV6SrcAddrJsonArray = new JsonArray();
            }
            ipV6SrcAddrJsonArray.add(element);
            LOG.debug("set validbit for ipv6src  :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valdfflowmatchIpv6Addr,
                    VtnServiceIpcConsts.V_MASK);

            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getIpcStructIpv6Value(valdfflowmatchIpv6Addr, VtnServiceIpcConsts.IPV6_ADDR_MASK)
                        .toString());
                if (null == ipV6SrcAddrMaskJsonArray) {
                    ipV6SrcAddrMaskJsonArray = new JsonArray();
                }
                ipV6SrcAddrMaskJsonArray.add(element);
                LOG.debug("set validbit for ipv6_mask:" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IPV6_DST.ordinal()) {

            final IpcStruct valdfflowmatchIpv6Addr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructIpv6Value(valdfflowmatchIpv6Addr, VtnServiceIpcConsts.IPV6_ADDR).toString());
            if (null == ipV6DstAddJsonArray) {
                ipV6DstAddJsonArray = new JsonArray();
            }
            ipV6DstAddJsonArray.add(element);
            LOG.debug("set validbit for ipv6dst  :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valdfflowmatchIpv6Addr,
                    VtnServiceIpcConsts.V_MASK);

            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getIpcStructIpv6Value(valdfflowmatchIpv6Addr, VtnServiceIpcConsts.IPV6_ADDR_MASK)
                        .toString());
                if (null == ipV6DstAddrMaskJsonArray) {
                    ipV6DstAddrMaskJsonArray = new JsonArray();
                }
                ipV6DstAddrMaskJsonArray.add(element);
                LOG.debug("set validbit for ipv6_mask:" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_TP_SRC.ordinal()) {

            final IpcStruct valDfFlowMatchTpPort = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowMatchTpPort, VtnServiceIpcConsts.TP_PORT).toString());
            if (null == l4SrcPortIcmpTypeJsonArray) {
                l4SrcPortIcmpTypeJsonArray = new JsonArray();
            }
            l4SrcPortIcmpTypeJsonArray.add(element);

            LOG.debug("set validbit for tpsrc :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valDfFlowMatchTpPort,
                    VtnServiceIpcConsts.V_MASK);

            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {

                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getIpcStructUint16Value(valDfFlowMatchTpPort, VtnServiceIpcConsts.TP_PORT_MASK)
                        .toString());
                if (null == l4SrcPortIcmpTypeMaskJsonArray) {
                    l4SrcPortIcmpTypeMaskJsonArray = new JsonArray();
                }
                l4SrcPortIcmpTypeMaskJsonArray.add(element);
                LOG.debug("set validbit for tpsrcmask :" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_TP_DST.ordinal()) {

            final IpcStruct valDfFlowMatchTpPort = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowMatchTpPort, VtnServiceIpcConsts.TP_PORT).toString());
            if (null == l4DstPortIcmpTypeJsonArray) {
                l4DstPortIcmpTypeJsonArray = new JsonArray();
            }
            l4DstPortIcmpTypeJsonArray.add(element);
            LOG.debug("set validbit for tpdst  :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valDfFlowMatchTpPort,
                    VtnServiceIpcConsts.V_MASK);

            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getIpcStructUint16Value(valDfFlowMatchTpPort, VtnServiceIpcConsts.TP_PORT_MASK)
                        .toString());

                if (null == l4DstPortIcmpTypeMaskJsonArray) {
                    l4DstPortIcmpTypeMaskJsonArray = new JsonArray();
                }
                l4DstPortIcmpTypeMaskJsonArray.add(element);
            }
        } else {
            LOG.debug("Type : invalid");
        }

    }
    if (null != inportJsonArray) {
        match.add(VtnServiceJsonConsts.INPORT, inportJsonArray);
    }
    if (null != dstMacJsonArray) {
        match.add(VtnServiceJsonConsts.MACDSTADDR, dstMacJsonArray);
    }
    if (dstMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.MACDSTADDR_MASK, dstMaskJsonArray);
    }
    if (srcMacJsonArray != null) {
        match.add(VtnServiceJsonConsts.MACSRCADDR, srcMacJsonArray);
    }
    if (srcMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.MACSRCADDR_MASK, srcMaskJsonArray);
    }
    if (macEtherTypeJsonArray != null) {
        match.add(VtnServiceJsonConsts.MACETHERTYPE, macEtherTypeJsonArray);
    }
    if (vlanIdJsonArray != null) {
        match.add(VtnServiceJsonConsts.VLAN_ID, vlanIdJsonArray);
    }
    if (vlanPriorityJsonArray != null) {
        match.add(VtnServiceJsonConsts.VLAN_PRIORITY, vlanPriorityJsonArray);
    }
    if (ipTosJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPTOS, ipTosJsonArray);
    }
    if (ipProtoJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPPROTO, ipProtoJsonArray);
    }
    if (ipSrcAddrJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPSRCADDR, ipSrcAddrJsonArray);
    }
    if (ipSrcAddrMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPSRCADDR_MASK, ipSrcAddrMaskJsonArray);
    }
    if (ipDstAddrJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPDSTADDR, ipDstAddrJsonArray);
    }
    if (ipDstAddrMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPDSTADDR_MASK, ipDstAddrMaskJsonArray);
    }
    if (ipV6SrcAddrJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPV6SRCADDR, ipV6SrcAddrJsonArray);
    }
    if (ipV6SrcAddrMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPV6SRCADDR_MASK, ipV6SrcAddrMaskJsonArray);
    }
    if (ipV6DstAddJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPV6DSTADDR, ipV6DstAddJsonArray);
    }
    if (ipV6DstAddrMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPV6DSTADDR_MASK, ipV6DstAddrMaskJsonArray);
    }
    if (l4SrcPortIcmpTypeJsonArray != null) {
        match.add(VtnServiceJsonConsts.L4SRCPORT_ICMPTYPE, l4SrcPortIcmpTypeJsonArray);
    }
    if (l4SrcPortIcmpTypeMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.L4SRCPORT_ICMPTYPE_MASK, l4SrcPortIcmpTypeMaskJsonArray);
    }
    if (l4DstPortIcmpTypeJsonArray != null) {
        match.add(VtnServiceJsonConsts.L4DSTPORT_ICMPTYPE, l4DstPortIcmpTypeJsonArray);
    }
    if (l4DstPortIcmpTypeMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.L4DSTPORT_ICMPTYPE_MASK, l4DstPortIcmpTypeMaskJsonArray);
    }
    LOG.debug("match Json :" + match);
    LOG.trace("getDataFlowMatchInfo completed");
    return match;
}

From source file:org.opendaylight.vtn.javaapi.ipc.conversion.IpcLogicalResponseFactory.java

License:Open Source License

/**
 * This method is Used to generate Action Flow info Json
 * /*from   www  .ja  v a 2 s .  co  m*/
 * @param responsePacket
 * @param requestBody
 * @param getType
 * @return JsonObject
 */
private JsonObject getDataFlowActionInfo(final IpcDataUnit[] responsePacket, final AtomicInteger index,
        final JsonObject controlerFlow, final IpcStruct valVtnDataFlowCmnStruct) {
    LOG.trace("getDataFlowActionInfo started");
    final int actionCount = Integer.parseInt(IpcDataUnitWrapper.getIpcStructUint32Value(valVtnDataFlowCmnStruct,
            VtnServiceIpcConsts.ACTION_COUNT));
    LOG.debug("acount_count:" + actionCount);
    final JsonObject action = new JsonObject();
    JsonArray outputPortJsonArray = null;
    JsonArray enqueuePortJsonArray = null;
    JsonArray queueIdJsonArray = null;
    JsonArray setDstMacAddrJsonArray = null;
    JsonArray setSrcMAcAddrJsonArray = null;
    JsonArray setVlanIdJsonArray = null;
    JsonArray setVlanPriorityJsonArray = null;
    JsonArray setDstAddrJsonArray = null;
    JsonArray setSrcIpAddrJsonArray = null;
    JsonArray setIpTosJsonArray = null;
    JsonArray setDstL4PortIcmpTypeJsonArray = null;
    JsonArray setSrcL4PortIcmpTypeJsonArray = null;
    JsonArray setIpV6DstAddrJsonArray = null;
    JsonArray setIpv6SrcAddrJsonArray = null;
    JsonArray setStripVlanJsonArray = null;
    JsonPrimitive element = null;
    int actionType;
    for (int i = 0; i < actionCount; i++) {

        final IpcStruct valDataFlowAction = (IpcStruct) responsePacket[index.getAndIncrement()];

        actionType = Integer.parseInt(
                IpcDataUnitWrapper.getIpcStructUint32Value(valDataFlowAction, VtnServiceIpcConsts.ACTION_TYPE));
        LOG.debug("actiontype :" + actionType);
        if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_OUTPUT.ordinal()) {

            final IpcStruct valDfFlowActionOutputPort = (IpcStruct) responsePacket[index.getAndIncrement()];
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint32Value(valDfFlowActionOutputPort, VtnServiceIpcConsts.OUTPUT_PORT)
                    .toString());
            if (null == outputPortJsonArray) {
                outputPortJsonArray = new JsonArray();
            }
            outputPortJsonArray.add(element);

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_ENQUEUE
                .ordinal()) {

            final IpcStruct valDfFlowActionEnqueuePort = (IpcStruct) responsePacket[index.getAndIncrement()];
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint32Value(valDfFlowActionEnqueuePort, VtnServiceIpcConsts.OUTPUT_PORT)
                    .toString());
            if (null == enqueuePortJsonArray) {
                enqueuePortJsonArray = new JsonArray();
            }
            enqueuePortJsonArray.add(element);

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowActionEnqueuePort, VtnServiceIpcConsts.ENQUEUE_ID)
                    .toString());
            if (null == queueIdJsonArray) {
                queueIdJsonArray = new JsonArray();

            }
            queueIdJsonArray.add(element);

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_DL_DST.ordinal()) {
            final IpcStruct valDfFlowActionSetDlAddr = (IpcStruct) responsePacket[index.getAndIncrement()];
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getMacAddress(valDfFlowActionSetDlAddr, VtnServiceIpcConsts.DL_ADDR).toString());
            if (null == setDstMacAddrJsonArray) {
                setDstMacAddrJsonArray = new JsonArray();
            }
            setDstMacAddrJsonArray.add(element);

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_DL_SRC.ordinal()) {
            final IpcStruct valDfFlowActionSetDlAddr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getMacAddress(valDfFlowActionSetDlAddr, VtnServiceIpcConsts.DL_ADDR).toString());
            if (null == setSrcMAcAddrJsonArray) {
                setSrcMAcAddrJsonArray = new JsonArray();
            }
            setSrcMAcAddrJsonArray.add(element);

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_VLAN_ID
                .ordinal()) {
            final IpcStruct valDfFlowActionSetVlanId = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowActionSetVlanId, VtnServiceIpcConsts.VLAN_ID).toString());

            if (null == setVlanIdJsonArray) {
                setVlanIdJsonArray = new JsonArray();

            }
            if (element.getAsString().equals(VtnServiceJsonConsts.VLAN_ID_65535)) {
                element = new JsonPrimitive(VtnServiceJsonConsts.EMPTY);
                setVlanIdJsonArray.add(element);
            } else {
                setVlanIdJsonArray.add(element);
            }
        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_VLAN_PCP
                .ordinal()) {
            final IpcStruct valDfFlowActionSetVlanPcp = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint8Value(valDfFlowActionSetVlanPcp, VtnServiceIpcConsts.VLAN_PCP)
                    .toString());
            if (null == setVlanPriorityJsonArray) {
                setVlanPriorityJsonArray = new JsonArray();

            }
            setVlanPriorityJsonArray.add(element);

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_STRIP_VLAN.ordinal()) {
            element = new JsonPrimitive(VtnServiceJsonConsts.TRUE);
            if (null == setStripVlanJsonArray) {
                setStripVlanJsonArray = new JsonArray();
            }
            setStripVlanJsonArray.add(element);
            index.getAndIncrement();
        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_IPV4_DST
                .ordinal()) {
            final IpcStruct valDfFlowActionSetIpv4 = (IpcStruct) responsePacket[index.getAndIncrement()];
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructIpv4Value(valDfFlowActionSetIpv4, VtnServiceIpcConsts.IPV4_ADDR).toString());

            if (null == setDstAddrJsonArray) {
                setDstAddrJsonArray = new JsonArray();

            }
            setDstAddrJsonArray.add(element);

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_IPV4_SRC
                .ordinal()) {
            final IpcStruct valDfFlowActionSetIpv4 = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructIpv4Value(valDfFlowActionSetIpv4, VtnServiceIpcConsts.IPV4_ADDR).toString());
            if (null == setSrcIpAddrJsonArray) {
                setSrcIpAddrJsonArray = new JsonArray();
            }
            setSrcIpAddrJsonArray.add(element);

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_IP_TOS.ordinal()) {
            final IpcStruct valDfFlowActionSetIpTos = (IpcStruct) responsePacket[index.getAndIncrement()];

            final String hexString = UnsignedInteger.toHexString(Long.valueOf(IpcDataUnitWrapper
                    .getIpcStructUint8Value(valDfFlowActionSetIpTos, VtnServiceIpcConsts.IP_TOS)));
            element = new JsonPrimitive("0x" + hexString);

            if (null == setIpTosJsonArray) {
                setIpTosJsonArray = new JsonArray();
            }
            setIpTosJsonArray.add(element);

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_TP_DST.ordinal()) {
            final IpcStruct valDfFlowActionSetTpPort = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowActionSetTpPort, VtnServiceIpcConsts.TP_PORT).toString());
            if (null == setDstL4PortIcmpTypeJsonArray) {
                setDstL4PortIcmpTypeJsonArray = new JsonArray();
            }
            setDstL4PortIcmpTypeJsonArray.add(element);

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_TP_SRC.ordinal()) {
            final IpcStruct valDfFlowActionSetTpPort = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowActionSetTpPort, VtnServiceIpcConsts.TP_PORT).toString());
            if (null == setSrcL4PortIcmpTypeJsonArray) {
                setSrcL4PortIcmpTypeJsonArray = new JsonArray();
            }
            setSrcL4PortIcmpTypeJsonArray.add(element);

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_IPV6_DST
                .ordinal()) {

            final IpcStruct valDfFlowActionSetIpv6 = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper.getIpcStructIpv6Value(valDfFlowActionSetIpv6,
                    VtnServiceIpcConsts.IPV6_ADDR));
            if (null == setIpV6DstAddrJsonArray) {
                setIpV6DstAddrJsonArray = new JsonArray();
            }
            setIpV6DstAddrJsonArray.add(element);

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_IPV6_SRC
                .ordinal()) {

            final IpcStruct valDfFlowActionSetIpv6 = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper.getIpcStructIpv6Value(valDfFlowActionSetIpv6,
                    VtnServiceIpcConsts.IPV6_ADDR));
            if (null == setIpv6SrcAddrJsonArray) {
                setIpv6SrcAddrJsonArray = new JsonArray();
            }
            setIpv6SrcAddrJsonArray.add(element);

        } else {
            LOG.debug("Type : invalid");
        }
    }
    if (outputPortJsonArray != null) {
        action.add(VtnServiceJsonConsts.OUTPUTPORT, outputPortJsonArray);
    }
    if (enqueuePortJsonArray != null) {
        action.add(VtnServiceJsonConsts.ENQUEUEPORT, enqueuePortJsonArray);
    }
    if (queueIdJsonArray != null) {
        action.add(VtnServiceJsonConsts.QUEUE_ID, queueIdJsonArray);
    }
    if (setDstMacAddrJsonArray != null) {
        action.add(VtnServiceJsonConsts.SETMACDSTADDR, setDstMacAddrJsonArray);
    }
    if (setSrcMAcAddrJsonArray != null) {
        action.add(VtnServiceJsonConsts.SETMACSRCADDR, setSrcMAcAddrJsonArray);
    }
    if (setVlanIdJsonArray != null) {
        action.add(VtnServiceJsonConsts.SETVLAN_ID, setVlanIdJsonArray);
    }
    if (setVlanPriorityJsonArray != null) {
        action.add(VtnServiceJsonConsts.SETVLAN_PRIORITY, setVlanPriorityJsonArray);
    }
    if (setStripVlanJsonArray != null) {
        action.add(VtnServiceJsonConsts.STRIPVLAN, setStripVlanJsonArray);
    }
    if (setDstAddrJsonArray != null) {
        action.add(VtnServiceJsonConsts.SETIPDSTADDR, setDstAddrJsonArray);
    }
    if (setSrcIpAddrJsonArray != null) {
        action.add(VtnServiceJsonConsts.SETIPSRCADDR, setSrcIpAddrJsonArray);
    }
    if (setIpTosJsonArray != null) {
        action.add(VtnServiceJsonConsts.SETIPTOS, setIpTosJsonArray);
    }
    if (setDstL4PortIcmpTypeJsonArray != null) {
        action.add(VtnServiceJsonConsts.SETL4DSTPORT_ICMPTYPE, setDstL4PortIcmpTypeJsonArray);
    }
    if (setSrcL4PortIcmpTypeJsonArray != null) {
        action.add(VtnServiceJsonConsts.SETL4SRCPORT_ICMPTYPE, setSrcL4PortIcmpTypeJsonArray);
    }
    if (setIpV6DstAddrJsonArray != null) {
        action.add(VtnServiceJsonConsts.SETIPV6DSTADDR, setIpV6DstAddrJsonArray);
    }
    if (setIpv6SrcAddrJsonArray != null) {
        action.add(VtnServiceJsonConsts.SETIPV6SRCADDR, setIpv6SrcAddrJsonArray);
    }
    LOG.debug("action json:" + action);
    return action;
}

From source file:org.opendaylight.vtn.javaapi.ipc.conversion.IpcPhysicalResponseFactory.java

License:Open Source License

private JsonObject getDataFlowActionInfo(final IpcDataUnit[] responsePacket, final AtomicInteger index,
        final JsonObject controlerFlow, final IpcStruct valDfDataFlowCmnStruct) {
    final int actionCount = Integer.parseInt(IpcDataUnitWrapper.getIpcStructUint32Value(valDfDataFlowCmnStruct,
            VtnServiceIpcConsts.ACTION_COUNT));
    LOG.debug("ACTION_COUNT:" + actionCount);

    // jsonObject action will holf all below json instance
    final JsonObject action = new JsonObject();
    // jsonObject objects are created only when required information from
    // response packet
    // here we have just used refernces
    JsonArray outputPortJsonArray = null;
    JsonArray enqueuePortJsonArray = null;
    JsonArray queueIdJsonArray = null;//w ww  .j  ava 2s.c  o  m
    JsonArray setMacDstAddrJsonArray = null;
    JsonArray setMacSrcAddrJsonArray = null;
    JsonArray setVlanIdJsonArray = null;
    JsonArray setVlanPriorityJsonArray = null;
    JsonArray setIpDstAddrJsonArray = null;
    JsonArray setIpSrcAddrJsonArray = null;
    JsonArray setIpTosJsonArray = null;
    JsonArray setL4DstPortIcmpTypeJsonArray = null;
    JsonArray setL4SrcPortIcmpTypeJsonArray = null;
    JsonArray setIpV6DstAddrJsonArray = null;
    JsonArray setIpv6SrcAddrJsonArray = null;
    JsonArray setStripVlanJsonArray = null;
    JsonPrimitive element = null;
    for (int i = 0; i < actionCount; i++) {
        final IpcStruct valDfFlowAction = (IpcStruct) responsePacket[index.getAndIncrement()];

        LOG.trace("getDataFlowActionInfo started");
        int actionType;
        // actiontype will help in resolving action as per response
        actionType = Integer.parseInt(
                IpcDataUnitWrapper.getIpcStructUint32Value(valDfFlowAction, VtnServiceIpcConsts.ACTION_TYPE));
        LOG.debug("actiontype :" + actionType);
        if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_OUTPUT.ordinal()) {
            final IpcStruct valDfFlowActionOutputPort = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint32Value(valDfFlowActionOutputPort, VtnServiceIpcConsts.OUTPUT_PORT)
                    .toString());
            if (null == outputPortJsonArray) {
                outputPortJsonArray = new JsonArray();
            }
            outputPortJsonArray.add(element);
            LOG.debug("set  out_port  ");

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_ENQUEUE
                .ordinal()) {
            final IpcStruct valDfFlowActionEnqueuePort = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint32Value(valDfFlowActionEnqueuePort, VtnServiceIpcConsts.OUTPUT_PORT)
                    .toString());
            if (null == enqueuePortJsonArray) {
                enqueuePortJsonArray = new JsonArray();
            }
            enqueuePortJsonArray.add(element);
            LOG.debug("set  enqueueport  ");

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowActionEnqueuePort, VtnServiceIpcConsts.ENQUEUE_ID)
                    .toString());
            if (null == queueIdJsonArray) {
                queueIdJsonArray = new JsonArray();
            }
            queueIdJsonArray.add(element);
            LOG.debug("set  enqueueid  ");

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_DL_DST.ordinal()) {
            final IpcStruct valDfFlowActionSetDlAddr = (IpcStruct) responsePacket[index.getAndIncrement()];
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getMacAddress(valDfFlowActionSetDlAddr, VtnServiceIpcConsts.DL_ADDR).toString());

            if (null == setMacDstAddrJsonArray) {
                setMacDstAddrJsonArray = new JsonArray();
            }
            setMacDstAddrJsonArray.add(element);
            LOG.debug("set macdst  ");

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_DL_SRC.ordinal()) {
            final IpcStruct valDfFlowActionSetDlAddr = (IpcStruct) responsePacket[index.getAndIncrement()];
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getMacAddress(valDfFlowActionSetDlAddr, VtnServiceIpcConsts.DL_ADDR).toString());
            if (null == setMacSrcAddrJsonArray) {
                setMacSrcAddrJsonArray = new JsonArray();
            }
            setMacSrcAddrJsonArray.add(element);
            LOG.debug("set macsrc  ");

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_VLAN_ID
                .ordinal()) {
            final IpcStruct valDfFlowActionSetVlanId = (IpcStruct) responsePacket[index.getAndIncrement()];
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowActionSetVlanId, VtnServiceIpcConsts.VLAN_ID).toString());
            if (null == setVlanIdJsonArray) {
                setVlanIdJsonArray = new JsonArray();
            }
            if (element.getAsString().equals(VtnServiceJsonConsts.VLAN_ID_65535)) {
                element = new JsonPrimitive(VtnServiceJsonConsts.EMPTY);
                setVlanIdJsonArray.add(element);
            } else {
                setVlanIdJsonArray.add(element);
            }

            LOG.debug("set vlan_id ");

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_VLAN_PCP
                .ordinal()) {
            final IpcStruct valDfFlowActionSetVlanPcp = (IpcStruct) responsePacket[index.getAndIncrement()];
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint8Value(valDfFlowActionSetVlanPcp, VtnServiceIpcConsts.VLAN_PCP)
                    .toString());
            if (null == setVlanPriorityJsonArray) {
                setVlanPriorityJsonArray = new JsonArray();
            }
            setVlanPriorityJsonArray.add(element);
            LOG.debug("set  vlanpriority   :");

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_STRIP_VLAN.ordinal()) {
            element = new JsonPrimitive(VtnServiceJsonConsts.TRUE);
            if (null == setStripVlanJsonArray) {
                setStripVlanJsonArray = new JsonArray();
            }
            setStripVlanJsonArray.add(element);
            index.getAndIncrement();

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_IPV4_SRC
                .ordinal()) {
            final IpcStruct valDfFlowActionSetIpv4 = (IpcStruct) responsePacket[index.getAndIncrement()];
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructIpv4Value(valDfFlowActionSetIpv4, VtnServiceIpcConsts.IPV4_ADDR).toString());
            if (null == setIpSrcAddrJsonArray) {
                setIpSrcAddrJsonArray = new JsonArray();
            }
            setIpSrcAddrJsonArray.add(element);
            LOG.debug("set ipsrc :");

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_IPV4_DST
                .ordinal()) {
            final IpcStruct valDfFlowActionSetIpv4 = (IpcStruct) responsePacket[index.getAndIncrement()];
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructIpv4Value(valDfFlowActionSetIpv4, VtnServiceIpcConsts.IPV4_ADDR).toString());
            if (null == setIpDstAddrJsonArray) {
                setIpDstAddrJsonArray = new JsonArray();
            }
            setIpDstAddrJsonArray.add(element);
            LOG.debug("set ipdst ");

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_IP_TOS.ordinal()) {
            final IpcStruct valDfFlowActionSetIpTos = (IpcStruct) responsePacket[index.getAndIncrement()];
            final String hexString = UnsignedInteger.toHexString(Long.valueOf(IpcDataUnitWrapper
                    .getIpcStructUint8Value(valDfFlowActionSetIpTos, VtnServiceIpcConsts.IP_TOS)));
            element = new JsonPrimitive("0x" + hexString);
            if (null == setIpTosJsonArray) {
                setIpTosJsonArray = new JsonArray();
            }
            setIpTosJsonArray.add(element);
            LOG.debug("set r iptos ");

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_TP_SRC.ordinal()) {
            final IpcStruct valDfFlowActionSetTpPort = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowActionSetTpPort, VtnServiceIpcConsts.TP_PORT).toString());
            if (null == setL4SrcPortIcmpTypeJsonArray) {
                setL4SrcPortIcmpTypeJsonArray = new JsonArray();
            }
            setL4SrcPortIcmpTypeJsonArray.add(element);
            LOG.debug("set  tpsrc ");

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_TP_DST.ordinal()) {
            final IpcStruct valDfFlowActionSetTpPort = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowActionSetTpPort, VtnServiceIpcConsts.TP_PORT).toString());
            if (null == setL4DstPortIcmpTypeJsonArray) {
                setL4DstPortIcmpTypeJsonArray = new JsonArray();
            }
            setL4DstPortIcmpTypeJsonArray.add(element);
            LOG.debug("set    tpdst  ");

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_IPV6_SRC
                .ordinal()) {

            final IpcStruct valDfFlowActionSetIpv6 = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper.getIpcStructIpv6Value(valDfFlowActionSetIpv6,
                    VtnServiceIpcConsts.IPV6_ADDR));
            if (null == setIpv6SrcAddrJsonArray) {
                setIpv6SrcAddrJsonArray = new JsonArray();
            }
            setIpv6SrcAddrJsonArray.add(element);
            LOG.debug("set   ipv6src  ");

        } else if (actionType == UncStructIndexEnum.UncDataflowFlowActionType.UNC_ACTION_SET_IPV6_DST
                .ordinal()) {

            final IpcStruct valDfFlowActionSetIpv6 = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper.getIpcStructIpv6Value(valDfFlowActionSetIpv6,
                    VtnServiceIpcConsts.IPV6_ADDR));
            if (null == setIpV6DstAddrJsonArray) {
                setIpV6DstAddrJsonArray = new JsonArray();
            }
            setIpV6DstAddrJsonArray.add(element);
            LOG.debug("set validBit for ipv6dst");
        }
        if (outputPortJsonArray != null) {
            action.add(VtnServiceJsonConsts.OUTPUTPORT, outputPortJsonArray);
        }
        if (enqueuePortJsonArray != null) {
            action.add(VtnServiceJsonConsts.ENQUEUEPORT, enqueuePortJsonArray);
        }
        if (queueIdJsonArray != null) {
            action.add(VtnServiceJsonConsts.QUEUE_ID, queueIdJsonArray);
        }
        if (setMacDstAddrJsonArray != null) {
            action.add(VtnServiceJsonConsts.SETMACDSTADDR, setMacDstAddrJsonArray);
        }
        if (setMacSrcAddrJsonArray != null) {
            action.add(VtnServiceJsonConsts.SETMACSRCADDR, setMacSrcAddrJsonArray);
        }
        if (setVlanIdJsonArray != null) {
            action.add(VtnServiceJsonConsts.SETVLAN_ID, setVlanIdJsonArray);
        }
        if (setVlanPriorityJsonArray != null) {
            action.add(VtnServiceJsonConsts.SETVLAN_PRIORITY, setVlanPriorityJsonArray);
        }
        if (setStripVlanJsonArray != null) {
            action.add(VtnServiceJsonConsts.STRIPVLAN, setStripVlanJsonArray);
        }
        if (setIpSrcAddrJsonArray != null) {
            action.add(VtnServiceJsonConsts.SETIPSRCADDR, setIpSrcAddrJsonArray);
        }
        if (setIpDstAddrJsonArray != null) {
            action.add(VtnServiceJsonConsts.SETIPDSTADDR, setIpDstAddrJsonArray);
        }
        if (setIpTosJsonArray != null) {
            action.add(VtnServiceJsonConsts.SETIPTOS, setIpTosJsonArray);
        }
        if (setL4SrcPortIcmpTypeJsonArray != null) {
            action.add(VtnServiceJsonConsts.SETL4SRCPORT_ICMPTYPE, setL4SrcPortIcmpTypeJsonArray);
        }
        if (setL4DstPortIcmpTypeJsonArray != null) {
            action.add(VtnServiceJsonConsts.SETL4DSTPORT_ICMPTYPE, setL4DstPortIcmpTypeJsonArray);
        }
        if (setIpv6SrcAddrJsonArray != null) {
            action.add(VtnServiceJsonConsts.SETIPV6SRCADDR, setIpv6SrcAddrJsonArray);
        }
        if (setIpV6DstAddrJsonArray != null) {
            action.add(VtnServiceJsonConsts.SETIPV6DSTADDR, setIpV6DstAddrJsonArray);
        }
    }
    LOG.debug("action json:" + action);
    LOG.trace("getDataFlowActionInfo completed");
    return action;

}

From source file:org.opendaylight.vtn.javaapi.ipc.conversion.IpcPhysicalResponseFactory.java

License:Open Source License

private JsonObject getDataFlowMatchInfo(final IpcDataUnit[] responsePacket, final AtomicInteger index,
        final byte validBit, final JsonObject controlerFlow, final IpcStruct valDfDataFlowCmnStruct) {
    LOG.trace("getDataFlowMatchInfo started");
    final int matchCount = Integer.parseInt(IpcDataUnitWrapper.getIpcStructUint32Value(valDfDataFlowCmnStruct,
            VtnServiceIpcConsts.MATCH_COUNT));
    LOG.debug("MATCH_COUNT:" + matchCount);
    // match JsonObject will hold all below jsonObject as per requiremnts
    final JsonObject match = new JsonObject();

    JsonArray inportJsonArray = null;/*from  www. j a va  2s . c  o  m*/
    JsonArray srcMacJsonArray = null;
    JsonArray dstMacJsonArray = null;
    JsonArray srcMaskJsonArray = null;
    JsonArray dstMaskJsonArray = null;
    JsonArray macEtherTypeJsonArray = null;
    JsonArray vlanIdJsonArray = null;
    JsonArray vlanPriorityJsonArray = null;
    JsonArray ipTosJsonArray = null;
    JsonArray ipProtoJsonArray = null;
    JsonArray ipDstAddrJsonArray = null;
    JsonArray ipDstAddrMaskJsonArray = null;
    JsonArray ipSrcAddrJsonArray = null;
    JsonArray ipSrcAddrMaskJsonArray = null;
    JsonArray l4DstPortIcmpTypeJsonArray = null;
    JsonArray l4DstPortIcmpTypeMaskJsonArray = null;
    JsonArray l4SrcPortIcmpTypeJsonArray = null;
    JsonArray l4SrcPortIcmpTypeMaskJsonArray = null;
    JsonArray ipV6DstAddJsonArray = null;
    JsonArray ipV6DstAddrMaskJsonArray = null;
    JsonArray ipV6SrcAddrJsonArray = null;
    JsonArray ipV6SrcAddrMaskJsonArray = null;
    JsonPrimitive element = null;
    for (int i = 0; i < matchCount; i++) {
        final IpcStruct valDfFlowMatchStruct = (IpcStruct) responsePacket[index.getAndIncrement()];

        final int matchtype = Integer.parseInt(IpcDataUnitWrapper.getIpcStructUint32Value(valDfFlowMatchStruct,
                VtnServiceIpcConsts.MATCH_TYPE));
        LOG.debug("MATCH TYPE:" + matchtype);
        // match type will help in resolving response in match info
        if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IN_PORT.ordinal()) {
            final IpcStruct valDfFlowMatchInPort = (IpcStruct) responsePacket[index.getAndIncrement()];
            // set inport
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint32Value(valDfFlowMatchInPort, VtnServiceIpcConsts.IN_PORT).toString());

            if (null == inportJsonArray) {
                inportJsonArray = new JsonArray();
            }
            inportJsonArray.add(element);
            LOG.debug("set validBit for in_port :" + validBit);

        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_DL_DST.ordinal()) {
            final IpcStruct valDfFlowMatchDlAddr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(
                    IpcDataUnitWrapper.getMacAddress(valDfFlowMatchDlAddr, VtnServiceIpcConsts.DL_ADDR));
            if (null == dstMacJsonArray) {
                dstMacJsonArray = new JsonArray();
            }
            dstMacJsonArray.add(element);
            LOG.debug("set validbit for macdst :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valDfFlowMatchDlAddr,
                    VtnServiceIpcConsts.V_MASK);

            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getMacAddress(valDfFlowMatchDlAddr, VtnServiceIpcConsts.DL_ADDR_MASK).toString());
                if (null == dstMaskJsonArray) {
                    dstMaskJsonArray = new JsonArray();
                }
                dstMaskJsonArray.add(element);
                LOG.debug("set validbit for macdst :" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_DL_SRC.ordinal()) {
            final IpcStruct valDfFlowMatchDlAddr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getMacAddress(valDfFlowMatchDlAddr, VtnServiceIpcConsts.DL_ADDR).toString());
            if (null == srcMacJsonArray) {
                srcMacJsonArray = new JsonArray();
            }
            srcMacJsonArray.add(element);
            LOG.debug("set validbit for macsrc  :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valDfFlowMatchDlAddr,
                    VtnServiceIpcConsts.V_MASK);

            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getMacAddress(valDfFlowMatchDlAddr, VtnServiceIpcConsts.DL_ADDR_MASK).toString());
                if (null == srcMaskJsonArray) {
                    srcMaskJsonArray = new JsonArray();
                }
                srcMaskJsonArray.add(element);
                LOG.debug("set validbit for macdst  :" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_DL_TYPE.ordinal()) {
            final IpcStruct valDfFlowMatchDlType = (IpcStruct) responsePacket[index.getAndIncrement()];
            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16HexaValue(valDfFlowMatchDlType, VtnServiceIpcConsts.DL_TYPE).toString());
            if (null == macEtherTypeJsonArray) {
                macEtherTypeJsonArray = new JsonArray();
            }
            macEtherTypeJsonArray.add(element);
            LOG.debug("set validbit for etherntype :" + validBit);

        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_VLAN_ID.ordinal()) {
            final IpcStruct valDfFlowMatchVlanVid = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowMatchVlanVid, VtnServiceIpcConsts.VLAN_ID).toString());
            if (null == vlanIdJsonArray) {
                vlanIdJsonArray = new JsonArray();
            }
            if (element.getAsString().equals(VtnServiceJsonConsts.VLAN_ID_65535)) {
                element = new JsonPrimitive(VtnServiceJsonConsts.EMPTY);
                vlanIdJsonArray.add(element);
            } else {
                vlanIdJsonArray.add(element);
            }

            LOG.debug("set validbit for vlan_id  :" + validBit);

        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_VLAN_PCP.ordinal()) {
            final IpcStruct valDfFlowMatchVlanpcp = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint8Value(valDfFlowMatchVlanpcp, VtnServiceIpcConsts.VLAN_PCP).toString());
            if (null == vlanPriorityJsonArray) {
                vlanPriorityJsonArray = new JsonArray();
            }
            vlanPriorityJsonArray.add(element);
            LOG.debug("set validbit for vlanpriority  :" + validBit);

        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IP_TOS.ordinal()) {

            final IpcStruct valDfFlowMatchIpTos = (IpcStruct) responsePacket[index.getAndIncrement()];

            final String hexString = UnsignedInteger.toHexString(Long.valueOf(IpcDataUnitWrapper
                    .getIpcStructUint8Value(valDfFlowMatchIpTos, VtnServiceIpcConsts.IP_TOS)));
            element = new JsonPrimitive("0x" + hexString);
            if (null == ipTosJsonArray) {
                ipTosJsonArray = new JsonArray();
            }
            ipTosJsonArray.add(element);
            LOG.debug("set validbit for iptos :" + validBit);

        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IP_PROTO.ordinal()) {

            final IpcStruct valDfFlowMatchIpProto = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint8Value(valDfFlowMatchIpProto, VtnServiceIpcConsts.IP_PROTO).toString());
            if (null == ipProtoJsonArray) {
                ipProtoJsonArray = new JsonArray();
            }
            ipProtoJsonArray.add(element);
            LOG.debug("set validbit for  ipproto :" + validBit);

        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IPV4_SRC.ordinal()) {
            final IpcStruct valDfFlowMatchIpv4Addr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructIpv4Value(valDfFlowMatchIpv4Addr, VtnServiceIpcConsts.IPV4_ADDR).toString());
            if (null == ipSrcAddrJsonArray) {
                ipSrcAddrJsonArray = new JsonArray();
            }
            ipSrcAddrJsonArray.add(element);
            LOG.debug("set validbit for ipsrc :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valDfFlowMatchIpv4Addr,
                    VtnServiceIpcConsts.V_MASK);
            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getIpcStructIpv4Value(valDfFlowMatchIpv4Addr, VtnServiceIpcConsts.IPV4_ADDR_MASK)
                        .toString());
                if (null == ipSrcAddrMaskJsonArray) {
                    ipSrcAddrMaskJsonArray = new JsonArray();

                }
                ipSrcAddrMaskJsonArray.add(element);
                LOG.debug("set validBit for ipv4_mask:" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IPV4_DST.ordinal()) {
            final IpcStruct valDfFlowMatchIpv4Addr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructIpv4Value(valDfFlowMatchIpv4Addr, VtnServiceIpcConsts.IPV4_ADDR).toString());
            if (null == ipDstAddrJsonArray) {
                ipDstAddrJsonArray = new JsonArray();
            }
            ipDstAddrJsonArray.add(element);
            LOG.debug("set validbit for ipdst  :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valDfFlowMatchIpv4Addr,
                    VtnServiceIpcConsts.V_MASK);
            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getIpcStructIpv4Value(valDfFlowMatchIpv4Addr, VtnServiceIpcConsts.IPV4_ADDR_MASK)
                        .toString());
                if (null == ipDstAddrMaskJsonArray) {
                    ipDstAddrMaskJsonArray = new JsonArray();
                }
                ipDstAddrMaskJsonArray.add(element);
                LOG.debug("set validbit for ipv4_mask:" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IPV6_SRC.ordinal()) {

            final IpcStruct valdfflowmatchIpv6Addr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructIpv6Value(valdfflowmatchIpv6Addr, VtnServiceIpcConsts.IPV6_ADDR).toString());
            if (null == ipV6SrcAddrJsonArray) {
                ipV6SrcAddrJsonArray = new JsonArray();
            }
            ipV6SrcAddrJsonArray.add(element);
            LOG.debug("set validbit for ipv6src  :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valdfflowmatchIpv6Addr,
                    VtnServiceIpcConsts.V_MASK);

            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getIpcStructIpv6Value(valdfflowmatchIpv6Addr, VtnServiceIpcConsts.IPV6_ADDR_MASK)
                        .toString());
                if (null == ipV6SrcAddrMaskJsonArray) {
                    ipV6SrcAddrMaskJsonArray = new JsonArray();
                }
                ipV6SrcAddrMaskJsonArray.add(element);
                LOG.debug("set validbit for ipv6_mask:" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_IPV6_DST.ordinal()) {

            final IpcStruct valdfflowmatchIpv6Addr = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructIpv6Value(valdfflowmatchIpv6Addr, VtnServiceIpcConsts.IPV6_ADDR).toString());
            if (null == ipV6DstAddJsonArray) {
                ipV6DstAddJsonArray = new JsonArray();
            }
            ipV6DstAddJsonArray.add(element);
            LOG.debug("set validbit for ipv6dst  :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valdfflowmatchIpv6Addr,
                    VtnServiceIpcConsts.V_MASK);

            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getIpcStructIpv6Value(valdfflowmatchIpv6Addr, VtnServiceIpcConsts.IPV6_ADDR_MASK)
                        .toString());
                if (null == ipV6DstAddrMaskJsonArray) {
                    ipV6DstAddrMaskJsonArray = new JsonArray();
                }
                ipV6DstAddrMaskJsonArray.add(element);
                LOG.debug("set validbit for ipv6_mask:" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_TP_SRC.ordinal()) {

            final IpcStruct valDfFlowMatchTpPort = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowMatchTpPort, VtnServiceIpcConsts.TP_PORT).toString());
            if (null == l4SrcPortIcmpTypeJsonArray) {
                l4SrcPortIcmpTypeJsonArray = new JsonArray();
            }
            l4SrcPortIcmpTypeJsonArray.add(element);

            LOG.debug("set validbit for tpsrc :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valDfFlowMatchTpPort,
                    VtnServiceIpcConsts.V_MASK);

            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {

                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getIpcStructUint16Value(valDfFlowMatchTpPort, VtnServiceIpcConsts.TP_PORT_MASK)
                        .toString());
                if (null == l4SrcPortIcmpTypeMaskJsonArray) {
                    l4SrcPortIcmpTypeMaskJsonArray = new JsonArray();
                }
                l4SrcPortIcmpTypeMaskJsonArray.add(element);
                LOG.debug("set validbit for tpsrcmask :" + validBit);
            }
        } else if (matchtype == UncStructIndexEnum.UncDataflowFlowMatchType.UNC_MATCH_TP_DST.ordinal()) {

            final IpcStruct valDfFlowMatchTpPort = (IpcStruct) responsePacket[index.getAndIncrement()];

            element = new JsonPrimitive(IpcDataUnitWrapper
                    .getIpcStructUint16Value(valDfFlowMatchTpPort, VtnServiceIpcConsts.TP_PORT).toString());
            if (null == l4DstPortIcmpTypeJsonArray) {
                l4DstPortIcmpTypeJsonArray = new JsonArray();
            }
            l4DstPortIcmpTypeJsonArray.add(element);
            LOG.debug("set validbit for tpdst  :" + validBit);

            final String s = IpcDataUnitWrapper.getIpcStructUint8Value(valDfFlowMatchTpPort,
                    VtnServiceIpcConsts.V_MASK);

            if (Integer.parseInt(s) == UncStructIndexEnum.Valid.UNC_VF_VALID.ordinal()) {
                element = new JsonPrimitive(IpcDataUnitWrapper
                        .getIpcStructUint16Value(valDfFlowMatchTpPort, VtnServiceIpcConsts.TP_PORT_MASK)
                        .toString());

                if (null == l4DstPortIcmpTypeMaskJsonArray) {
                    l4DstPortIcmpTypeMaskJsonArray = new JsonArray();
                }
                l4DstPortIcmpTypeMaskJsonArray.add(element);
            }
        } else {
            LOG.debug("Type : invalid");
        }

    }
    if (null != inportJsonArray) {
        match.add(VtnServiceJsonConsts.INPORT, inportJsonArray);
    }
    if (null != dstMacJsonArray) {
        match.add(VtnServiceJsonConsts.MACDSTADDR, dstMacJsonArray);
    }
    if (dstMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.MACDSTADDR_MASK, dstMaskJsonArray);
    }
    if (srcMacJsonArray != null) {
        match.add(VtnServiceJsonConsts.MACSRCADDR, srcMacJsonArray);
    }
    if (srcMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.MACSRCADDR_MASK, srcMaskJsonArray);
    }
    if (macEtherTypeJsonArray != null) {
        match.add(VtnServiceJsonConsts.MACETHERTYPE, macEtherTypeJsonArray);
    }
    if (vlanIdJsonArray != null) {
        match.add(VtnServiceJsonConsts.VLAN_ID, vlanIdJsonArray);
    }
    if (vlanPriorityJsonArray != null) {
        match.add(VtnServiceJsonConsts.VLAN_PRIORITY, vlanPriorityJsonArray);
    }
    if (ipTosJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPTOS, ipTosJsonArray);
    }
    if (ipProtoJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPPROTO, ipProtoJsonArray);
    }
    if (ipSrcAddrJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPSRCADDR, ipSrcAddrJsonArray);
    }
    if (ipSrcAddrMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPSRCADDR_MASK, ipSrcAddrMaskJsonArray);
    }
    if (ipDstAddrJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPDSTADDR, ipDstAddrJsonArray);
    }
    if (ipDstAddrMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPDSTADDR_MASK, ipDstAddrMaskJsonArray);
    }
    if (ipV6SrcAddrJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPV6SRCADDR, ipV6SrcAddrJsonArray);
    }
    if (ipV6SrcAddrMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPV6SRCADDR_MASK, ipV6SrcAddrMaskJsonArray);
    }
    if (ipV6DstAddJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPV6DSTADDR, ipV6DstAddJsonArray);
    }
    if (ipV6DstAddrMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.IPV6DSTADDR_MASK, ipV6DstAddrMaskJsonArray);
    }
    if (l4SrcPortIcmpTypeJsonArray != null) {
        match.add(VtnServiceJsonConsts.L4SRCPORT_ICMPTYPE, l4SrcPortIcmpTypeJsonArray);
    }
    if (l4SrcPortIcmpTypeMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.L4SRCPORT_ICMPTYPE_MASK, l4SrcPortIcmpTypeMaskJsonArray);
    }
    if (l4DstPortIcmpTypeJsonArray != null) {
        match.add(VtnServiceJsonConsts.L4DSTPORT_ICMPTYPE, l4DstPortIcmpTypeJsonArray);
    }
    if (l4DstPortIcmpTypeMaskJsonArray != null) {
        match.add(VtnServiceJsonConsts.L4DSTPORT_ICMPTYPE_MASK, l4DstPortIcmpTypeMaskJsonArray);
    }
    LOG.debug("match Json :" + match);
    LOG.trace("getDataFlowMatchInfo completed");
    return match;
}