当前位置: 首页>>代码示例>>Java>>正文


Java Policy类代码示例

本文整理汇总了Java中org.onosproject.segmentrouting.Policy的典型用法代码示例。如果您正苦于以下问题:Java Policy类的具体用法?Java Policy怎么用?Java Policy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Policy类属于org.onosproject.segmentrouting包,在下文中一共展示了Policy类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPolicy

import org.onosproject.segmentrouting.Policy; //导入依赖的package包/类
/**
 * Create a new segment routing policy.
 *
 * @param input JSON stream for policy to create
 * @return status of the request - OK if the policy is created,
 * @throws IOException if JSON processing fails
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response createPolicy(InputStream input) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode policyJson = (ObjectNode) mapper.readTree(input);
    SegmentRoutingService srService = get(SegmentRoutingService.class);
    Policy policyInfo = POLICY_CODEC.decode(policyJson, this);

    if (policyInfo.type() == Policy.Type.TUNNEL_FLOW) {
        srService.createPolicy(policyInfo);
        return Response.ok().build();
    } else {
        return Response.serverError().build();
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:PolicyWebResource.java

示例2: encode

import org.onosproject.segmentrouting.Policy; //导入依赖的package包/类
@Override
public ObjectNode encode(Policy policy, CodecContext context) {
    final ObjectNode result = context.mapper().createObjectNode()
            .put(POLICY_ID, policy.id());

    result.put(PRIORITY, policy.priority());
    result.put(TYPE, policy.type().toString());

    if (policy.dstIp() != null) {
        result.put(DST_IP, policy.dstIp());
    }
    if (policy.srcIp() != null) {
        result.put(SRC_IP, policy.srcIp());
    }
    if (policy.ipProto() != null) {
        result.put(PROTO_TYPE, policy.ipProto());
    }

    int srcPort = policy.srcPort() & 0xffff;
    if (policy.srcPort() != 0) {
        result.put(SRC_PORT, srcPort);
    }
    int dstPort = policy.dstPort() & 0xffff;
    if (policy.dstPort() != 0) {
        result.put(DST_PORT, dstPort);
    }
    if (policy.type() == Policy.Type.TUNNEL_FLOW) {
        result.put(TUNNEL_ID, ((TunnelPolicy) policy).tunnelId());
    }

    return result;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:33,代码来源:PolicyCodec.java

示例3: getPolicy

import org.onosproject.segmentrouting.Policy; //导入依赖的package包/类
/**
 * Get all segment routing policies.
 * Returns an array of segment routing policies.
 *
 * @return status of OK
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getPolicy() {
    SegmentRoutingService srService = get(SegmentRoutingService.class);
    List<Policy> policies = srService.getPolicies();
    ObjectNode result = new ObjectMapper().createObjectNode();
    result.set("policy", new PolicyCodec().encode(policies, this));

    return ok(result.toString()).build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:PolicyWebResource.java

示例4: removePolicy

import org.onosproject.segmentrouting.Policy; //导入依赖的package包/类
/**
 * Delete a segment routing policy.
 *
 * @param input JSON stream for policy to delete
 * @return 204 NO CONTENT if the policy is removed
 * @throws IOException if JSON is invalid
 */
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
public Response removePolicy(InputStream input) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode policyJson = (ObjectNode) mapper.readTree(input);
    SegmentRoutingService srService = get(SegmentRoutingService.class);
    Policy policyInfo = POLICY_CODEC.decode(policyJson, this);
    // TODO: Check the result
    srService.removePolicy(policyInfo);

    return Response.noContent().build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:20,代码来源:PolicyWebResource.java

示例5: printPolicy

import org.onosproject.segmentrouting.Policy; //导入依赖的package包/类
private void printPolicy(Policy policy) {
    if (policy.type() == Policy.Type.TUNNEL_FLOW) {
        print(FORMAT_MAPPING_TUNNEL, policy.id(), policy.type(), policy.priority(),
                policy.srcIp(), policy.srcPort(), policy.dstIp(), policy.dstPort(),
                (policy.ipProto() == null) ? "" : policy.ipProto(),
                ((TunnelPolicy) policy).tunnelId());
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:9,代码来源:PolicyListCommand.java

示例6: decode

import org.onosproject.segmentrouting.Policy; //导入依赖的package包/类
@Override
public Policy decode(ObjectNode json, CodecContext context) {

    String pid = json.path(POLICY_ID).asText();
    String type = json.path(TYPE).asText();
    int priority = json.path(PRIORITY).asInt();
    String dstIp = json.path(DST_IP).asText();
    String srcIp = json.path(SRC_IP).asText();
    String tunnelId = json.path(TUNNEL_ID).asText();
    String protoType = json.path(PROTO_TYPE).asText();
    short srcPort = json.path(SRC_PORT).shortValue();
    short dstPort = json.path(DST_PORT).shortValue();

    if (json.path(POLICY_ID).isMissingNode() || pid == null) {
        // TODO: handle errors
        return null;
    }

    TunnelPolicy.Builder tpb = TunnelPolicy.builder().setPolicyId(pid);
    if (!json.path(TYPE).isMissingNode() && type != null &&
            Policy.Type.valueOf(type).equals(Policy.Type.TUNNEL_FLOW)) {

        if (json.path(TUNNEL_ID).isMissingNode() || tunnelId == null) {
            return null;
        }

        tpb.setTunnelId(tunnelId);
        tpb.setType(Policy.Type.valueOf(type));

        if (!json.path(PRIORITY).isMissingNode()) {
            tpb.setPriority(priority);
        }
        if (dstIp != null) {
            tpb.setDstIp(dstIp);
        }
        if (srcIp != null) {
            tpb.setSrcIp(srcIp);
        }
        if (protoType != null) {
            tpb.setIpProto(protoType);
        }
        if (dstPort != 0) {
            tpb.setDstPort(dstPort);
        }
        if (srcPort != 0) {
            tpb.setSrcPort(srcPort);
        }
    }

    return tpb.build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:52,代码来源:PolicyCodec.java

示例7: execute

import org.onosproject.segmentrouting.Policy; //导入依赖的package包/类
@Override
protected void execute() {

    SegmentRoutingService srService =
            AbstractShellCommand.get(SegmentRoutingService.class);

    TunnelPolicy.Builder tpb = TunnelPolicy.builder().setPolicyId(policyId);
    tpb.setPriority(priority);
    tpb.setType(Policy.Type.valueOf(policyType));

    if (srcIp != null) {
        tpb.setSrcIp(srcIp);
    }
    if (dstIp != null) {
        tpb.setDstIp(dstIp);
    }
    if (srcPort != 0) {
        tpb.setSrcPort(srcPort);
    }
    if (dstPort != 0) {
        tpb.setDstPort(dstPort);
    }
    if (!proto.equals("ip")) {
        tpb.setIpProto(proto);
    }
    if (Policy.Type.valueOf(policyType) == Policy.Type.TUNNEL_FLOW) {
        if (tunnelId == null) {
            error("tunnel ID must be specified for TUNNEL_FLOW policy");
            return;
        }
        tpb.setTunnelId(tunnelId);
    }
    PolicyHandler.Result result = srService.createPolicy(tpb.build());

    switch (result) {
        case POLICY_EXISTS:
            error("the same policy exists");
            break;
        case ID_EXISTS:
            error("the same policy ID exists");
            break;
        case TUNNEL_NOT_FOUND:
            error("the tunnel is not found");
            break;
        case UNSUPPORTED_TYPE:
            error("the policy type specified is not supported");
            break;
        default:
            break;
    }

}
 
开发者ID:shlee89,项目名称:athena,代码行数:53,代码来源:PolicyAddCommand.java

示例8: execute

import org.onosproject.segmentrouting.Policy; //导入依赖的package包/类
@Override
protected void execute() {

    SegmentRoutingService srService =
            AbstractShellCommand.get(SegmentRoutingService.class);

    TunnelPolicy.Builder tpb = TunnelPolicy.builder().setPolicyId(policyId);
    tpb.setPriority(priority);
    tpb.setType(Policy.Type.valueOf(policyType));

    if (srcIp != null) {
        tpb.setSrcIp(srcIp);
    }
    if (dstIp != null) {
        tpb.setDstIp(dstIp);
    }
    if (srcPort != 0) {
        tpb.setSrcPort(srcPort);
    }
    if (dstPort != 0) {
        tpb.setDstPort(dstPort);
    }
    if (!"ip".equals(proto)) {
        tpb.setIpProto(proto);
    }
    if (Policy.Type.valueOf(policyType) == Policy.Type.TUNNEL_FLOW) {
        if (tunnelId == null) {
            error("tunnel ID must be specified for TUNNEL_FLOW policy");
            return;
        }
        tpb.setTunnelId(tunnelId);
    }
    PolicyHandler.Result result = srService.createPolicy(tpb.build());

    switch (result) {
        case POLICY_EXISTS:
            error("the same policy exists");
            break;
        case ID_EXISTS:
            error("the same policy ID exists");
            break;
        case TUNNEL_NOT_FOUND:
            error("the tunnel is not found");
            break;
        case UNSUPPORTED_TYPE:
            error("the policy type specified is not supported");
            break;
        default:
            break;
    }

}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:53,代码来源:PolicyAddCommand.java


注:本文中的org.onosproject.segmentrouting.Policy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。