/** * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * 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 */ package org.opendaylight.openflowplugin.impl.statistics.services; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService; import org.opendaylight.openflowplugin.impl.services.RequestInputUtils; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder; final class FlowsInTableService extends AbstractSimpleService { FlowsInTableService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { super(requestContextStack, deviceContext, GetFlowStatisticsFromFlowTableOutput.class); } @Override protected OfHeader buildRequest(final Xid xid, final GetFlowStatisticsFromFlowTableInput input) { final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); mprFlowRequestBuilder.setTableId(input.getTableId()); if (input.getOutPort() != null) { mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue()); } else { mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); } if (input.getOutGroup() != null) { mprFlowRequestBuilder.setOutGroup(input.getOutGroup()); } else { mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); } if (input.getCookie() != null) { mprFlowRequestBuilder.setCookie(input.getCookie().getValue()); } else { mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); } if (input.getCookieMask() != null) { mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue()); } else { mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); } // convert and inject match final short version = getVersion(); final DeviceContext deviceContext = getDeviceContext(); MatchReactor.getInstance().convert(input.getMatch(), version, mprFlowRequestBuilder, deviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId()); // Set request body to main multipart request multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build()); final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader( MultipartType.OFPMPFLOW, xid.getValue(), version); mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); return mprInput.build(); } }