4 package org.opendaylight.controller.packetcable.provider.processors;
6 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
7 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
8 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.traffic.profile.rev140908.TrafficProfileBestEffortAttributes;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.traffic.profile.rev140908.TrafficProfileDocsisServiceClassNameAttributes;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.traffic.profile.rev140908.TrafficProfileFlowspecAttributes;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.traffic.profile.rev140908.traffic.profile.best.effort.attributes.BeAuthorizedEnvelope;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.traffic.profile.rev140908.traffic.profile.best.effort.attributes.BeCommittedEnvelope;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.traffic.profile.rev140908.traffic.profile.best.effort.attributes.BeReservedEnvelope;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.*;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.tcp.match.ranges.attributes.TcpMatchRanges;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.udp.match.ranges.attributes.UpdMatchRanges;
19 import org.pcmm.gates.IClassifier;
20 import org.pcmm.gates.IExtendedClassifier;
21 import org.pcmm.gates.ITrafficProfile;
22 import org.pcmm.gates.impl.BestEffortService;
23 import org.pcmm.gates.impl.BestEffortService.BEEnvelop;
24 import org.pcmm.gates.impl.DOCSISServiceClassNameTrafficProfile;
25 import org.pcmm.gates.impl.ExtendedClassifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import java.net.InetAddress;
30 import java.net.UnknownHostException;
34 * PacketCable data processor
37 public class PCMMDataProcessor {
39 private Logger logger = LoggerFactory.getLogger(PCMMDataProcessor.class);
41 public ITrafficProfile process(TrafficProfileBestEffortAttributes bestEffort) {
42 BestEffortService trafficProfile = new BestEffortService(BestEffortService.DEFAULT_ENVELOP);
43 getBEAuthorizedEnvelop(bestEffort, trafficProfile);
44 getBEReservedEnvelop(bestEffort, trafficProfile);
45 getBECommittedEnvelop(bestEffort, trafficProfile);
46 return trafficProfile;
50 public ITrafficProfile process(TrafficProfileDocsisServiceClassNameAttributes docsis) {
51 DOCSISServiceClassNameTrafficProfile trafficProfile = new DOCSISServiceClassNameTrafficProfile();
52 trafficProfile.setServiceClassName(docsis.getServiceClassName());
53 return trafficProfile;
57 public ITrafficProfile process(TrafficProfileFlowspecAttributes flowSpec) {
58 throw new UnsupportedOperationException("Not impelemnted yet");
61 public IClassifier process(Match match) {
62 ExtendedClassifier classifier = new ExtendedClassifier();
63 // classifier.setProtocol(IClassifier.Protocol.NONE);
64 getUdpMatchRangeValues(match.getAugmentation(UdpMatchRangesRpcAddFlow.class), classifier);
65 getTcpMatchRangesValues(match.getAugmentation(TcpMatchRangesRpcAddFlow.class), classifier);
66 SubscriberIdRpcAddFlow subId = match.getAugmentation(SubscriberIdRpcAddFlow.class);
67 Ipv6Address ipv6Address = subId.getSubscriberId().getIpv6Address();
68 if (ipv6Address != null)
70 classifier.setDestinationIPAddress(InetAddress.getByName(ipv6Address.getValue()));
71 } catch (UnknownHostException e) {
72 logger.error(e.getMessage());
75 Ipv4Address ipv4Address = subId.getSubscriberId().getIpv4Address();
76 if (ipv4Address != null)
78 classifier.setDestinationIPAddress(InetAddress.getByName(ipv4Address.getValue()));
79 } catch (UnknownHostException e) {
80 logger.error(e.getMessage());
85 private void getBECommittedEnvelop(TrafficProfileBestEffortAttributes bestEffort, BestEffortService trafficProfile) {
86 BEEnvelop committedEnvelop = trafficProfile.getCommittedEnvelop();
87 BeCommittedEnvelope beCommittedEnvelope = bestEffort.getBeCommittedEnvelope();
88 if (beCommittedEnvelope.getTrafficPriority() != null)
89 committedEnvelop.setTrafficPriority(beCommittedEnvelope.getTrafficPriority().byteValue());
91 committedEnvelop.setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
92 if (beCommittedEnvelope.getMaximumTrafficBurst() != null)
93 committedEnvelop.setMaximumTrafficBurst(beCommittedEnvelope.getMaximumTrafficBurst().intValue());
95 committedEnvelop.setMaximumTrafficBurst(BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
96 if (beCommittedEnvelope.getRequestTransmissionPolicy() != null)
97 committedEnvelop.setRequestTransmissionPolicy(beCommittedEnvelope.getRequestTransmissionPolicy().intValue());
99 // committedEnvelop.setRequestTransmissionPolicy(PCMMGlobalConfig.BETransmissionPolicy);
100 if (beCommittedEnvelope.getMaximumSustainedTrafficRate() != null)
101 committedEnvelop.setMaximumSustainedTrafficRate(beCommittedEnvelope.getMaximumSustainedTrafficRate().intValue());
103 // committedEnvelop.setMaximumSustainedTrafficRate(PCMMGlobalConfig.DefaultLowBestEffortTrafficRate);
106 private void getBEReservedEnvelop(TrafficProfileBestEffortAttributes bestEffort, BestEffortService trafficProfile) {
107 BEEnvelop reservedEnvelop = trafficProfile.getReservedEnvelop();
108 BeReservedEnvelope beReservedEnvelope = bestEffort.getBeReservedEnvelope();
109 if (beReservedEnvelope.getTrafficPriority() != null)
110 reservedEnvelop.setTrafficPriority(beReservedEnvelope.getTrafficPriority().byteValue());
112 reservedEnvelop.setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
113 if (beReservedEnvelope.getMaximumTrafficBurst() != null)
114 reservedEnvelop.setMaximumTrafficBurst(beReservedEnvelope.getMaximumTrafficBurst().intValue());
116 reservedEnvelop.setMaximumTrafficBurst(BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
117 if (beReservedEnvelope.getRequestTransmissionPolicy() != null)
118 reservedEnvelop.setRequestTransmissionPolicy(beReservedEnvelope.getRequestTransmissionPolicy().intValue());
119 if (beReservedEnvelope.getMaximumSustainedTrafficRate() != null)
120 reservedEnvelop.setMaximumSustainedTrafficRate(beReservedEnvelope.getMaximumSustainedTrafficRate().intValue());
123 private void getBEAuthorizedEnvelop(TrafficProfileBestEffortAttributes bestEffort, BestEffortService trafficProfile) {
124 BEEnvelop authorizedEnvelop = trafficProfile.getAuthorizedEnvelop();
125 BeAuthorizedEnvelope beAuthorizedEnvelope = bestEffort.getBeAuthorizedEnvelope();
126 if (beAuthorizedEnvelope.getTrafficPriority() != null)
127 authorizedEnvelop.setTrafficPriority(beAuthorizedEnvelope.getTrafficPriority().byteValue());
129 authorizedEnvelop.setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
130 if (beAuthorizedEnvelope.getMaximumTrafficBurst() != null)
131 authorizedEnvelop.setMaximumTrafficBurst(beAuthorizedEnvelope.getMaximumTrafficBurst().intValue());
133 authorizedEnvelop.setMaximumTrafficBurst(BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
134 if (beAuthorizedEnvelope.getRequestTransmissionPolicy() != null)
135 authorizedEnvelop.setRequestTransmissionPolicy(beAuthorizedEnvelope.getRequestTransmissionPolicy().intValue());
136 if (beAuthorizedEnvelope.getMaximumSustainedTrafficRate() != null)
137 authorizedEnvelop.setMaximumSustainedTrafficRate(beAuthorizedEnvelope.getMaximumSustainedTrafficRate().intValue());
140 private void getTcpMatchRangesValues(TcpMatchRangesAttributes tcpRange, IExtendedClassifier classifier) {
141 short srcPortStart, srcPortEnd, dstPortStart, dstPortEnd;
142 srcPortStart = srcPortEnd = dstPortStart = dstPortEnd = 0;
143 if (tcpRange != null) {
144 // classifier.setProtocol(IClassifier.Protocol.TCP);
145 TcpMatchRanges tcpMatchRanges = tcpRange.getTcpMatchRanges();
146 PortNumber tcpDestinationPortStart = tcpMatchRanges.getTcpDestinationPortStart();
147 if (tcpDestinationPortStart != null && tcpDestinationPortStart.getValue() != null)
148 dstPortStart = tcpDestinationPortStart.getValue().shortValue();
149 PortNumber tcpSourcePortStart = tcpMatchRanges.getTcpSourcePortStart();
150 if (tcpSourcePortStart != null && tcpSourcePortStart.getValue() != null)
151 srcPortStart = tcpSourcePortStart.getValue().shortValue();
152 PortNumber tcpDestinationPortEnd = tcpMatchRanges.getTcpDestinationPortEnd();
153 if (tcpDestinationPortEnd != null && tcpDestinationPortEnd.getValue() != null)
154 dstPortEnd = tcpDestinationPortEnd.getValue().shortValue();
155 PortNumber tcpSourcePortEnd = tcpMatchRanges.getTcpSourcePortEnd();
156 if (tcpSourcePortEnd != null && tcpSourcePortEnd.getValue() != null)
157 srcPortEnd = tcpSourcePortEnd.getValue().shortValue();
159 classifier.setDestinationPortStart(dstPortStart);
160 classifier.setSourcePortStart(srcPortStart);
161 classifier.setDestinationPortEnd(dstPortEnd);
162 classifier.setSourcePortEnd(srcPortEnd);
165 private void getUdpMatchRangeValues(UdpMatchRangesAttributes updRange, IExtendedClassifier classifier) {
166 short srcPortStart, srcPortEnd, dstPortStart, dstPortEnd;
167 srcPortStart = srcPortEnd = dstPortStart = dstPortEnd = 0;
168 if (updRange != null) {
169 // classifier.setProtocol(IClassifier.Protocol.UDP);
170 UpdMatchRanges updMatchRanges = updRange.getUpdMatchRanges();
171 PortNumber udpDestinationPortStart = updMatchRanges.getUdpDestinationPortStart();
172 if (udpDestinationPortStart != null && udpDestinationPortStart.getValue() != null)
173 dstPortStart = udpDestinationPortStart.getValue().shortValue();
174 PortNumber udpSourcePortStart = updMatchRanges.getUdpSourcePortStart();
175 if (udpSourcePortStart != null && udpSourcePortStart.getValue() != null)
176 srcPortStart = udpSourcePortStart.getValue().shortValue();
177 PortNumber udpDestinationPortEnd = updMatchRanges.getUdpDestinationPortEnd();
178 if (udpDestinationPortEnd != null && udpDestinationPortEnd.getValue() != null)
179 dstPortEnd = udpDestinationPortEnd.getValue().shortValue();
180 PortNumber udpSourcePortEnd = updMatchRanges.getUdpSourcePortEnd();
181 if (udpSourcePortEnd != null && udpSourcePortEnd.getValue() != null)
182 srcPortEnd = udpSourcePortEnd.getValue().shortValue();
184 classifier.setDestinationPortStart(dstPortStart);
185 classifier.setSourcePortStart(srcPortStart);
186 classifier.setDestinationPortEnd(dstPortEnd);
187 classifier.setSourcePortEnd(srcPortEnd);